Level 2
up
Is there any better way to do something like this? I would like to pre-map some stuff in my controller, instead putting it into the view:
$articles = $articles
->paginate(15)
->appends(request()->all());
$articles->setCollection(
$articles->getCollection()
->map(function($item, $key)
{
$item->userstat = $item->userstats->first();
return $item;
})
);
return view('video.index', compact('articles'));
Please or to participate in this conversation.