Level 75
Aug 7, 2020
4
Level 15
Pagination
I have a method on my Supplier model that looks like:
public function getAllDiariesAttribute()
{
$products = $this->products();
$weeks = $products->with('weeks.diary.latestWeek')->get()->pluck('weeks')->collapse()->pluck('diary');
return $weeks->merge($products->with('diaries.latestWeek')->get()->pluck('diaries'))->flatten()->unique('id');
}
Products are attached to the diary itself or to the weeks(which are attached to the diary)
Any thoughts on how you could make this an eloquent query to be able to do pagination on the results?
Please or to participate in this conversation.