Tôi đang cố trả lại một đối tượng Contract
và tất cả các đối tượng liên quan là Project
. Tôi có thể trả lại tất cả các số Contract
s nhưng khi tôi cố gắng để có được hợp đồng của Project
, tôi nhận được lỗi "Lớp 'EstimateProject' không tìm thấy". Tôi đã chạy composer dump-autoload
để tải lại ánh xạ lớp, nhưng tôi vẫn gặp lỗi. Bất kỳ ý tưởng? Đây là thiết lập lớp học của tôi:Không tìm thấy lớp Laravel với một-nhiều-nhiều
EDIT: Chỉ muốn thêm rằng LaravelBook\Ardent\Ardent\
là một phần mở rộng của Model.php Laravel của. Nó thêm xác thực để mô hình hóa trên hàm Save
. Tôi đã làm cho Ardent mở rộng một plugin mà tôi đã thêm vào đó là một phiên bản MongoDB của ORlo Eloquent.
EstimateContract.php
<?php namespace Test\Tools;
use LaravelBook\Ardent\Ardent;
class EstimateContract extends Ardent {
// This sets the value on the Mongodb plugin's '$collection'
protected $collection = 'Contracts';
public function projects()
{
return $this->hasMany('EstimateProject', 'contractId');
}
}
EstimateProject.php
<?php namespace Test\Tools;
use LaravelBook\Ardent\Ardent;
class EstimateProject extends Ardent {
// This sets the value on the Mongodb plugin's '$collection'
protected $collection = 'Projects';
public function contract()
{
return $this->belongsTo('EstimateContract', 'contractId');
}
}
EstimateContractController.php
<?php
use \Test\Tools\EstimateContract;
class EstimateContractsController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$contracts = EstimateContract::all();
echo $contracts;
foreach($contracts as $contract)
{
if($contract->projects)
{
echo $contract->projects;
}
}
}
}
thử đặt 'sử dụng \ Test \ Tools \ EstimateProject;' trong 'EstimateContractController.php' –
@TryingTobemyself không may, tôi đã cố gắng mà không có kết quả. – Thelonias
thử đặt 'sử dụng \ Test \ Tools \ EstimateProject;' trong 'EstimateContract.php' –