dimanche 1 avril 2018

sort collection by custom new value

I have this query below, I need to sort the Cars by a value that is collected from another table:

$cars = Car::paginate(100);
$cars->getCollection()->transform(function ($item) {
.....
....
...
$item['buy_date'] = Transaction::where('id', $item->buy_transaction)->first()->date;

});

I tried:

->sortBy('buy_date')

But it didn't sort the result.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire