Php 未找到具有一对多的Laravel类

Php 未找到具有一对多的Laravel类,php,mongodb,laravel,laravel-4,Php,Mongodb,Laravel,Laravel 4,我正试图返回一个对象合同及其所有相关的项目。我可以返回所有的合同,但是当我试图获取合同的项目时,我得到了一个“Class'EstimateProject'not found”错误。我已经运行了composer dump autoload来重新加载类映射,但仍然会出现错误。有什么想法吗?这是我的课程设置: EDIT:只想添加LaravelBook\Ardent\Ardent\是Laravel的Model.php的扩展。它在Save函数中向模型添加验证。我已经让Ardent扩展了我添加的另一个插件,

我正试图返回一个对象
合同
及其所有相关的
项目
。我可以返回所有的
合同
,但是当我试图获取合同的
项目
时,我得到了一个“Class'EstimateProject'not found”错误。我已经运行了
composer dump autoload
来重新加载类映射,但仍然会出现错误。有什么想法吗?这是我的课程设置:

EDIT:只想添加
LaravelBook\Ardent\Ardent\
是Laravel的Model.php的扩展。它在
Save
函数中向模型添加验证。我已经让Ardent扩展了我添加的另一个插件,它是一个MongoDB版本的雄辩ORM

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 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');
   }
}
<?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;
            }
        }
     }
}

为了让它工作,我需要在我的EstimateContract模型中完全限定EstimateProject字符串

解决方案是将其从:

return $this->hasMany('EstimateProject', 'contractId'); 


您必须使用完全限定名称,但我在使用前斜杠而不是后斜杠时遇到了相同的错误:

//Correct
return $this->hasMany('Fully\Qualified\ClassName');
//Incorrect
return $this->hasMany('Fully/Qualified/ClassName');

尝试放置
use\Test\Tools\EstimateProject
EstimateContractController.php
@TryingTobemyself不幸的是,我已经试过了,但没有用EstimateContract.php
@TryingTobemyself中的code>也尝试了这个方法。请注意,这是因为我输入的方法名称不正确<代码>返回EstimateContract::with('projects')->get()工作。谢谢你的帮助
//Correct
return $this->hasMany('Fully\Qualified\ClassName');
//Incorrect
return $this->hasMany('Fully/Qualified/ClassName');