laravel-cross-eloquent-search
laravel-cross-eloquent-search copied to clipboard
Sort results by nested relationship
I want to sort main result set by relation in an order.. eg lets say a post has many tags i want to get all post but they should be sorted by their tags using eager load.
Something likes this? (from the Laravel docs)
$orderBySubquery = Flight::select('arrived_at')
->whereColumn('destination_id', 'destinations.id')
->orderBy('arrived_at', 'desc')
->limit(1);
Search::add(Destination::class, 'location', $orderBySubquery)->get('Amsterdam');
Yea so all destinations result would be ordered by flight order by
For future readers of this issue, I recommend looking at this package: https://github.com/kirschbaum-development/eloquent-power-joins