Учитывая приведенный ниже запрос, как вы можете добавить больше условий где / add (mysql), до 4 полей?
$query = Profile::select('field1', field2', 'field3, 'field4', DB::raw('SUM(likes.like) AS total'))
->leftJoin('users', 'users.id', '=', 'profiles.user_id')
->leftJoin('likes', 'likes.profile_id', '=', 'profiles.user_id')
->whereNotNull('users.id')
->groupBy('users.id')
->orderBy('users.last_login_at', 'DESC')
->get();
Я попытался добавить, как показано ниже, что приводит к 405 ошибкам:
$query = Profile::select('field1', field2', 'field3, 'field4', DB::raw('SUM(likes.like) AS total'))
->leftJoin('users', 'users.id', '=', 'profiles.user_id')
->leftJoin('likes', 'likes.profile_id', '=', 'profiles.user_id')
->whereNotNull('users.id');
if ($field1 != 'condition') {
$query->where('profiles.field1', $field1)
}
$query->groupBy('users.id')
->orderBy('users.last_login_at', 'DESC')
->get();