微博列表中的 @include ('statuses._status', ['user' => $status->user]) $status->user 是如何关联获取到用户信息的?

我试着找了一下
@foreach] ($feed_items as $status) @include('statuses._status', ['user' => $status->user]) @endforeach

StaticPagesController 控制器 home 方法
if(Auth::check()) { $feed_items = Auth::user()->feed()->paginate(10); }
return view('static_pages/home',compact('feed_items'));
User.php 里面的 feed 方法 和调用的statuse方法
public function feed() { return $this->statuses() ->orderBy('created_at', 'desc'); }
public function statuses() { return $this->hasMany(Status::class,'user_id','id'); }
从那个步骤开始把用户信息放到$feed_items 里面的 ? 我打印的$feed_items 只是包含了基本的微博数据.知道的朋友们帮我看看....

桃知夭夭
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

可以去看一下文档,预加载模块
https://learnku.com/docs/laravel/5.5/eloqu...

file
file
这个是动态属性,预加载的方式更加快。

6年前 评论
讨论数量: 6

可以去看一下文档,预加载模块
https://learnku.com/docs/laravel/5.5/eloqu...

file
file
这个是动态属性,预加载的方式更加快。

6年前 评论
Summer

作为开发者,请学习下 https://github.com/riku/Markdown-Syntax-CN...

6年前 评论

@AmberLavigne 233,你不优雅的markdown被大大翻牌子了

6年前 评论

可以在vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php找到getRelationValue这个方法,有这么一句:

// If the "attribute" exists as a method on the model, we will just assume it is a relationship and will load and return results from the query and hydrate the relationship's value on the "relationships" array.
if (method_exists($this, $key)) {
    return $this->getRelationshipFromMethod($key);
}

这里的$key就是'user',$this就是微博实例。

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!