lundi 30 mai 2016

How to sort this eloquent collection?

I am currently working on a beer application with checkins. A user checkin represents a beer he/she has drank. I am now dealing with checkins of the currently logged in user and also the checkins of their friends which I have set up through a friendship table.

I am grabbing a collection of user friends and an instance of the currently logged in user and I am adding them together like so:

// merge the currently logged in user with their friends
$users = $users->add($user);

I now have a collection of the logged in user and their friends and ultimately want to display some sort of timeline with their checkins. My main issue is that whenever I want to use something like this:

@foreach($users as $user)
     @foreach($user->checkins as $checkin)
         // my code
     @endforeach
 @endforeach

I get all users checkins but I am getting the output chunked/grouped per user. Preferably I would just like to sort them on age and not per user so I can create an actual timeline. Now I am getting a block of all of user 1's checkins followed by a block of user 2's checkins, etc.

How can I prevent this behaviour and simply show the latest checkin down to the oldest one?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Vr0k92
via IFTTT

Aucun commentaire:

Enregistrer un commentaire