在一个视图中的两个模型,包括分页,排序和排序

时间:2019-02-26 17:24:29

标签: laravel-5.4

我有两种模式(客户和供应商)。 现在,我想将其花在一个视图中。

它可以工作,但是不幸的是,没有名称和日期的排序和排序

    $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);

那是数组转储

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"
}

如何按名称而不是按Model :: customer和/或Model :: vendors对输出进行排序?

模型可以混合吗?

希腊 史蒂文

0 个答案:

没有答案