Hi,
I have a pivot table that links users to products. The table has timestamps that are updated when I attach a product to a user.
When retrieving the products via something like User::products()
. Is there a way to order on the date the relationship was created? ie, the created_at
column in product_user
Cheers
James
Yes you can do something like this
User::with(array('products' => function($query) {
$query->orderBy('created_at', 'desc');
}))->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community