📌  相关文章
📜  laravel eloquent 获得 x 个结果 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:48.240000             🧑  作者: Mango

代码示例1
//First you can use a Paginator. This is as simple as:
$allUsers = User::paginate(15);
$someUsers = User::where('votes', '>', 100)->paginate(15);

//The variables will contain an instance of Paginator class. all of your data will be stored under data key.

//Or you can do something like:
//Old versions Laravel.

Model::all()->take(10)->get();

//Newer version Laravel.
Model::all()->take(10);

//For more reading consider these links:

//pagination docs - http://laravel.com/docs/pagination#usage
//passing data to views - http://laravel.com/docs/responses#views
// Eloquent basic usage - http://laravel.com/docs/eloquent#basic-usage
//A cheat sheet - http://cheats.jesse-obrien.ca/


//Another way to do it is using a limit method:
Listing::limit(10)->get();

//this worked as well IN LARAVEL 8
Model::query()->take(10)->get();