How to organize queries to dB in c dynamic amount of conditions?

There is here such clumsy(XS how to record using relaxen) dB query,
$ads = DB::table('ads')
->join('ad_translates','ads.id','=','ad_translates.ad_id')
 ->join('users', 'ads.user_id', '=', 'users.id')
 ->join('cities', 'ads.city_id', '=', 'cities.id')
 ->join('country_translates', 'cities.country_id', '=', 'country_translates.country_id')
 ->join('city_translates', 'ads.city_id', '=', 'city_translates.city_id')
 ->join('category_translates', 'ads.category_id', '=', 'category_translates.category_id')
 ->Where('country_translates.language_id', $lang_id)
 ->Where('city_translates.language_id', $lang_id)
 ->Where('category_translates.language_id', $lang_id)
->where('country_translates.country_id',$country_id)
->where('cities.id',$city_id)
 ->select('ads.*','ad_translates.name','ad_translates.description','users.name AS username', 'country_translates.country_id AS country_id',
 'country_translates.name AS country', 'city_translates.name AS city', 'category_translates.name AS category')
 ->paginate(3);

In the query conditions,
->where('country_translates.country_id',$country_id)
->where('cities.id',$city_id)

may be completely absent or may be present only on one condition c country_id. Turns 3 a situation when there are no conditions, one condition or two conditions. How to organize it in the code to make it kosher
April 3rd 20 at 17:28
1 answer
April 3rd 20 at 17:30
Solution
$arr = [
 ['first_name', '=', 'last_name'],
 ['updated_at', '>', 'created_at']
];
$users = DB::table('users')->whereColumn($arr)->get();
What a mess... - rebecca_Abernathy commented on April 3rd 20 at 17:33
@rebecca_Abernathy, yeah, such passion in the documentation, write as many eyes on the forehead climb. - lina.OHara54 commented on April 3rd 20 at 17:36
@lina.OHara54, how do you know if you didn't read? - rebecca_Abernathy commented on April 3rd 20 at 17:39
@rebecca_Abernathy, from, honourable sir, that the example I copied from the documentation for version 5. I advise you to go and read the documentation, and then to tell who read and who is not) - lina.OHara54 commented on April 3rd 20 at 17:42
@lina.OHara54, well, if you read something copied would be the right example ->when(...). - rebecca_Abernathy commented on April 3rd 20 at 17:45
@rebecca_Abernathy, it's not that. Or I not correctly understood the question. The author knows better. - lina.OHara54 commented on April 3rd 20 at 17:48
@lina.OHara54,
The author knows better.
the author barely understands what is going on, it is clear from his questions. It any example will do. - rebecca_Abernathy commented on April 3rd 20 at 17:51

Find more questions by tags Laravel