My issue right now is whenever I create two new assignments, the last Post
in the merged collection disappears.
// Here is the code:
@foreach($user->groups as $group)
<?php
$all = $group->posts->merge($group->assignments)->merge($group->quizzes);
$sorted = $all->sortByDesc('created_at');
?>
@foreach($sorted as $item)
<?php
$val = get_class($item);
switch ($val)
{
case 'App\Post':
?>
Post:<br>
<?php
break;
case 'App\Assignment':
?>
Assignment:<br>
<?php
break;
case 'App\Quiz':
?>
Quiz:<br>
<?php
break;
}
?>
@endforeach
@endforeach
So how can I properly merge various Eloquent Collections together, then sort them by the latest?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iIpuzR
via IFTTT
Aucun commentaire:
Enregistrer un commentaire