Laravel 5.1 - 无法通过ORM访问关系

时间:2016-08-16 19:02:46

标签: eloquent laravel-5.1

我有两个模型类,定义如下:

class Event extends Model
{
        use SoftDeletes;

    protected $dates = ['deleted_at'];


public function user()
{
    return $this->belongsTo('App\User');
}
public function transfers()
{
    return $this->hasMany('App\Transfer');
    }

}




class Transfers extends Model

{
    use SoftDeletes;
/**
 * The attributes that should be mutated to dates.
 *
 * @var array
 */
protected $dates = ['deleted_at'];


public function event()
{
    return $this->belongsTo('App\Event');
    }
}

我正在尝试使用以下代码从Transfers对象访问Event

 public function filter()
    {
         $id = request()->input('id');
          $event = \App\Event::where([['id', '=', $id],
                                                 ['deleted_at', '=', NULL],
                                                ['user_id', '=', auth()->user()->id]])->first();

         echo $event->transfers->count();
}

然而,它导致如下例外

  

致命错误:未找到“App \ Transfer”类   d:\工作\ HC \ hcserver \供应商\ laravel \框架的\ src \照亮\数据库\雄辩\ Model.php   在线876

请告知如何摆脱此异常

提前致谢。

0 个答案:

没有答案