[英]Paginate Results of Model Laravel
我在Laravel 5.3中有分頁問題
編碼:
public function deals()
{
return $this->belongsToMany('App\Models\ListsDeals', 'list_has_deals' , 'list_id', 'deal_id')->withPivot('list_id');
}
public function form_edit_list( $id ){
$list = Lists::find( $id );
PAGINATE THIS -----> $deals = $list->deals;
$user = User::find( $list->id_user );
$categoriesArray = ListsCategories::all();
$featuresArray = ListsFeatures::all();
$images = ListsGalleries::all();
return view( "admin.forms.form_edit_list" )
->with( "list", $list )
->withCategoriesArray( $categoriesArray )
->withFeaturesArray( $featuresArray )
->withImages( $images )
->with( "user", $user );
}
我已經試過了
$deals = $list->deals->paginate(5);
我如何區分交易結果?
因為分頁不是那種方法。
我相信你可以添加paginate()
調用deals()
關系定義(這將分頁的所有用途)。
這可能不是理想的,所以您也可以執行$deals = $list->deals()->paginate();
$list->deals
是項目的集合,而$list->deals()
是一個雄辯的查詢生成器實例,您可以在獲取重新使用的內容之前對其進行進一步的調整。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.