datarecall
1 month ago

Pagination

Posted 1 month ago by datarecall

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 sign in or create an account to participate in this conversation.