我正在尝试返回一个对象Contract
并且所有它都是相关的Project
。我可以退回所有的Contract
s,但是当我尝试获取合同时Project
,我收到“找不到类 'EstimateProject'”错误。我已经运行composer dump-autoload
重新加载类映射,但我仍然得到错误。有任何想法吗?这是我的班级设置:
编辑:只是想添加它LaravelBook\Ardent\Ardent\
是 Laravel 的 Model.php 的扩展。Save
它为函数的模型添加了验证。我已经让 Ardent 扩展了我添加的另一个插件,它是 Eloquent ORM 的 MongoDB 版本。
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');
}
}
估计项目.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;
}
}
}
}