0

I have two models (customers and vendors). Now I want to spend this in one view.

It works, but unfortunately without sort and order for name, date

    $request = request();
    $input = $request->input();

    $collection = collect(
        [
            Customers::all(),
            Vendors::all()
        ]
    );

    $addresses = $collection->flatten();

    $items = $addresses instanceof Collection ? $addresses : Collection::make($addresses);

    $page = null;
    $page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
    $perPage = $request->get('limit', setting('general.list_limit', '25'));
    $path = 'http://my.domain.com/address';

    return (new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page))->setPath($path);

Thats the array dump

LengthAwarePaginator {#1785 ▼
  #total: 13
  #lastPage: 1
  #items: Collection {#1809 ▼
    #items: array:13 [▼
      0 => Customers {#1769 ▶}
      1 => Customers {#1726 ▶}
      2 => Vendors {#1539 ▶}
      3 => Vendors {#1752 ▶}
      4 => Vendors {#1542 ▶}
      5 => Vendors {#1751 ▶}
      6 => Vendors {#1543 ▶}
      7 => Vendors {#1750 ▶}
      8 => Vendors {#1545 ▶}
      9 => Vendors {#1749 ▶}
      10 => Vendors {#1547 ▶}
      11 => Vendors {#1748 ▶}
      12 => Vendors {#1548 ▶}
    ]
  }
  #perPage: "25"
  #currentPage: 1
  #path: "http://my.domain.com/address"
  #query: []
  #fragment: null
  #pageName: "page"
}

How can I sort the output by name and not by Model::customer and/or Model::vendors?

the models can be mixed out?

Greez Steven

tognit
  • 23
  • 5
  • Possible duplicate of [How can I paginate a merged collection in Laravel 5?](https://stackoverflow.com/questions/30420505/how-can-i-paginate-a-merged-collection-in-laravel-5) – danboh Feb 26 '19 at 19:38
  • Thanks for the link, the pagination I have done. Now the sort and order is still missing. – tognit Mar 02 '19 at 13:10
  • 1
    for paginate collection and sorting see this : https://stackoverflow.com/a/56142421/6901246 – Rohallah Hatami Dec 28 '20 at 14:50

0 Answers0