我想知道如何在with
函数中传递变量。代码如下:
这里我们有控制器代码:
$id = 2;
$user = User::where('userToken', '=', $token)
->with('userPost($id)')
->first();
这里我们有模型代码:
public function userPost($id) {
return $this->hasMany(PostPhotos::class, 'user_id', 'id')
->with(['getlikes' => function($q) use ($id) {
$q->where('likeStatus', '=', 'like');
$q->where('userclick_id', '=', $id);
}]);
}
你能帮我吗?