Laravel 8 Eloquent 分頁(yè)

2021-07-19 11:16 更新

你還可以對(duì) Eloquent 查詢(xún)結(jié)果進(jìn)行分頁(yè)。在下面的例子中,我們將 User 模型按每頁(yè) 15 條分頁(yè)。如你所見(jiàn),其語(yǔ)法與查詢(xún)構(gòu)造器分頁(yè)基本相同:

$users = App\Models\User::paginate(15); 

你還可以在調(diào)用 paginate 之前,在查詢(xún)中設(shè)置諸如 where 從句的其它約束:

$users = User::where('votes', '>', 100)->paginate(15); 

你還可以在 Eloquent 分頁(yè)中使用 simplePaginate 方法:

$users = User::where('votes', '>', 100)->simplePaginate(15); 


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)