- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
Article and User has many to one relationship
$article_no_user = Cache::remember("article_no_user_{$id}", 5, function() use ($id) {
return Article::find($id)->first();
});
echo $article_no_user->user->name; //event article cached, this will query user table every time
$article = Cache::remember("article_{$id}", 5, function() use ($id) {
return Article::with('user')->find($id)->first();
});
echo $article->user->name; //this will use cache
留言