【问题标题】:Call to undefined method Illuminate\Database\Eloquent\Collection::with()调用未定义的方法 Illuminate\Database\Eloquent\Collection::with()
【发布时间】:2014-11-20 19:12:48
【问题描述】:

我的路线代码

 return View::make('test')->with('foo', foo::all()->with('foos', 'bars'));

为什么会抛出这个异常?

【问题讨论】:

标签: laravel laravel-4 eloquent


【解决方案1】:

函数all() 执行查询,以便您获得一个集合。您必须在查询生成器实例上调用 with。这意味着你应该这样做:

foo::with('foos', 'bars')->get();

此外,按照惯例,类以大写字母开头,因此应该是 Foo ;)

【讨论】:

    猜你喜欢
    • 2015-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 2016-03-10
    • 2016-10-20
    相关资源
    最近更新 更多