本文介绍了路由模型绑定的热切加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的控制器功能
public function show(NovelRequest $request, Novel $novel)
{
// load the chapters
$novel->chapters;
// return the detail view of a novel
return view('novels.show', compact('novel'));
}
我收到一个新对象,因为我正在使用路由模型绑定。但是,除了这些章节之外,我还想加载更多内容。因为如果我现在执行类似的操作,将会引起很多请求
I receive a novel object because i m using route model binding. However, I'd like to load more than the chapters. Since it would cause many request if i now do something like
$novel->chapters;
$novel->bookmarks;
...
我想知道是否有一种方法可以在我加载多重关系时已经有了新奇的对象。通常我会喜欢这样的东西
I wondered if theres a way to load "multiple" relations when i already have the novel object. Usually i would to something like
Novel::with('chapters', 'bookmarks')-> ...
但是,我已经有了新奇的物体,所以我不想看它
However, I already have the novel object so i would like to not look it up a second time.
推荐答案
有 。
语法为 $ novel-> load(章,书签);
这篇关于路由模型绑定的热切加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!