0

I fetch some data with

$merchants = Merchant::selectRaw($query)->with(...)->whereHas(...)->where(...)->paginate(10);

Now, I want to pluck() this data before passing it to blade. This doesn't work:

$collection = collect($merchants);

When I fetch the data with

$merchants = Merchant::selectRaw($query)->with(...)->whereHas(...)->where(...)->get();

I can use $collection = collect($merchants); without any problemns, but pagination does not work for sure.

So, how can I combine paginate() with collect() or rahter access paginated data in the controller before passing it to blade?

Dong3000
  • 566
  • 2
  • 7
  • 24

1 Answers1

3

You can get the collection using

$collection = $merchants->getCollection();

or get data as an array using

$array = $merchants->items();
chanafdo
  • 5,016
  • 3
  • 29
  • 46