Бесполезно order
в закрытии join
.
Вам необходимо добавить orderBy
после join
:
$brand = Brand::where('slug','=',$slugurl)
->with(['stores' => function($q){
$q->where('status', 1)
->join('cities', 'cities.id', '=', 'stores.city_id')
->orderBy('cities.sort_number', 'DESC');
}])
->firstOrFail();
Этот запрос преобразовать в raw sql is:
select * from brands where slug = ? limit 1;
select * from stores
join cities on cities.id = stores.city_id
where status = 1 and stores.brand_id in (?)
order by cities.sort_number desc;