Level 73
@joha you can use ->whereHas to filter them out: https://laravel.com/docs/master/eloquent-relationships#querying-relationship-existence
$cars = Cars::when($selected_city_exist, function ($query, $selected_city) {
return $query->where('city', (int)$selected_city);
})
->whereHas('owners', function($query) {
$query->where('birthday', '<=', now()->subYears(25));
})
->when($type_exist, function ($query, $type) {
return $query->where('type', (int)$type);
})->paginate(50);