我在laravel 5中使用Eloquent编写了一个查询,其中我使用了with Clause
,但是当我在laravel query Builder中编写了查询,但是找不到任何with Clause
时,请告诉我带有Clause的替代项在查询生成器中。
这是我雄辩的查询:
$invitedOnActivity = $this->isInvitedOnActivity($activity->id, $activity->user_id, $authUser->id);
if($invitedOnActivity == true && $activity->activity_privacy == 'invite_only'){
if($activity->activity_privacy_visible == 0)
{
$activity = Activity::where('id', $activity->id)->with(['joins' => function($query) use ($userFriendIds) {
$query->whereIn('user_id', $userFriendIds);
}])->withCount(['joins' => function ($query) use ($userFriendIds) {
$query->whereIn('user_id', $userFriendIds);
}])->first();
// return response()->json(['q'=>$activity],200);
}
else if ($activity->activity_privacy_visible == 1 && in_array($activity->user_id, $userFriendIds))
{
$activity = Activity::where('id', $activity->id)->where('activity_privacy_visible', 1)->with(['joins' => function($query) use ($userFriendIds) {
$query->whereIn('user_id', $userFriendIds);
}])->withCount(['joins' => function ($query) use ($userFriendIds){
$query->whereIn('user_id', $userFriendIds);
}])->first();
// return response()->json(['w'=>$activity],200);
}
else {
continue;
}
}
我希望此查询在查询生成器中更改。这是我将尝试的查询,但我认为它不起作用。
if($invitedOnActivity == false){
$activity = DB::table('activities')
->where('id', $activity->id)
->where('activity_privacy', 'invite_only')
->where('activity_privacy_visible', 0)
->get();
}
在此查询中,我找不到with子句的替代项。请帮我。预先感谢。