参考文档:模型关联-反向关联 belongsToor
-
模型层
app/Post.php
public function user() { return $this->belongsTo('AppUser','user_id','id'); }
-
控制器层
app/Http/Controllers/PostController.php
$user_id = Auth::id();
-
视图层
{$list->user->name}}
$list->user不带括号,返回关联关系的对象