【发布时间】:2015-09-17 05:07:28
【问题描述】:
我有这个 Comment 模型与属于关系。
class Comment extends Model
{
public function user()
{
return $this->belongsTo('App\User');
}
}
在我的控制器中:
public function store(Request $request)
{
$comment = $this->dispatch(
new StoreCommentCommand($request->body, Auth::user()->id, $request->post_id)
);
return $comment;
}
当我返回 $comment 时,我还想要嵌套用户对象,我该怎么做?
【问题讨论】:
标签: json rest laravel eloquent