Laravel 延迟加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43776415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Lazy load
提问by Jamie
I've got this in my controller:
我的控制器中有这个:
return view('message.Message')->with([
'reactions' => $message->reaction->load('user, user.corporation')->paginate(2)
]);
But the lazy load ->load()
. does not work. I receive:
但是懒加载->load()
。不起作用。我收到:
Call to undefined relationship [user, user] on model [App\Core\Reaction\Reaction].
But the user relation is definitly there!:
但是用户关系肯定存在!:
public function user()
{
return $this->belongsTo(User::class);
}
How could I get this to work?
我怎么能让这个工作?
采纳答案by Amarnasan
You are not using the right parameters in the call to load. I think you want
您没有在调用加载中使用正确的参数。我想你想要
load('user', 'user.corporation')
负载('用户','user.corporation')
Actually I think if you load 'user.corporation', 'user' is automatically loaded, so you only need
其实我觉得如果你加载'user.corporation','user'会自动加载,所以你只需要
load('user.corporation')
负载('用户。公司')