[英]Paginate Results of Model Laravel
I have a problem with pagination in laravel 5.3 我在Laravel 5.3中有分页问题
The code: 编码:
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 );
}
I have tried this, 我已经试过了
$deals = $list->deals->paginate(5);
How can I paginate the results of deals ? 我如何区分交易结果?
Because paginate is not a method of that. 因为分页不是那种方法。
I believe you can add the paginate()
call to the deals()
relationship definition (which will paginate all uses of it). 我相信你可以添加
paginate()
调用deals()
关系定义(这将分页的所有用途)。
That may not be ideal, so you can also do $deals = $list->deals()->paginate();
这可能不是理想的,所以您也可以执行
$deals = $list->deals()->paginate();
$list->deals
is a collection of items, while $list->deals()
is an Eloquent query builder instance you can make further adjustments to before fetching the reuslts. $list->deals
是项目的集合,而$list->deals()
是一个雄辩的查询生成器实例,您可以在获取重新使用的内容之前对其进行进一步的调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.