I am trying to get two Models, concat them to a collection, and order them within the concatenation by
updated_at, to create an already sorted (by updated_at) foreach loop within my view, and just check on the Model instance, then trigger a partial based on the Model.
$users = $partner->users()->get(); $events = $partner->events()->get(); $collection = $users->concat($events)->orderBy('updated_at', 'desc')->limit(5)->get();
This results in
Collection::orderBy does not exist
Logic within my view:
@foreach($collection as $object) @if($object instanceof App\Models\User) // User related partial @elseif($object instanceof App\Models\Event) // Event related partial @endif @endforeach
How can I order the concatenated Collection by
Limit on a collection also won't work. Is the thought even possible?
Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.