没有找到一对多的Laravel课程

The*_*ias 9 php mongodb laravel laravel-4

我正在尝试返回一个对象Contract而且所有这些都是相关的Project.我可以返回所有Contracts但是当我试图得到合同时Project,我得到一个"Class'EstimateProject'not found"错误.我已经运行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');
     }
  }
Run Code Online (Sandbox Code Playgroud)

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');
   }
}
Run Code Online (Sandbox Code Playgroud)

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;
            }
        }
     }
}
Run Code Online (Sandbox Code Playgroud)

The*_*ias 25

为了使其工作,我需要在EstimateContract模型中完全限定EstimateProject字符串.

解决方案是改变它:

return $this->hasMany('EstimateProject', 'contractId'); 
Run Code Online (Sandbox Code Playgroud)

至

return $this->hasMany('\Test\Tools\EstimateProject', 'contractId');
Run Code Online (Sandbox Code Playgroud)