how to paginate query
Original Query
$sort = File::latest()->get()->groupBy(function($item)
{
return $item->date;
});
I tried this, and it doesn't work. it only gives one item
$sort = File::latest()->paginate(50)->groupBy(function($item)
{
return $item->date;
});
Why are you trying to group the items? What will they be used for?
You can get the items for the page like this
$items = File::latest()->paginate(50)->items();
@Sinnbeck I'm grouping items by date, so items appear underneath dates they were created
@tomasosho You can try this then
$sort = File::latest()->paginate(50)->items()->groupBy(function($item)
{
return $item->date;
});
@Sinnbeck
Error
Call to a member function groupBy() on array
@tomasosho Convert to collection then
$sort = collect(File::latest()->paginate(50)->items())->groupBy(function($item)
{
return $item->date;
});
@tomasosho Well I suggest you pass this stuff next to your pagination so you have each one
$pagination =File::latest()->paginate(50);
$grouped = collect($pagination->items())->groupBy(function($item)
{
return $item->date;
});
return view('myview', compact('pagination', 'grouped'));
Then it probably should be
$sort = File::latest()>groupBy(function($item)
{
return $item->date;
})->paginate(50);
@Tray2 This was the first one i tried.
But let me try again
ErrorException
stripos() expects parameter 1 to be string, object given
Please or to participate in this conversation.