简体   繁体   中英

How to get specific rows in Laravel?

Say I have a users table which contains 1000's of users! So, how can I grab the users with id starting from 15 to 48, for instance?

You can write simple MySQL Query

DB::select('SELECT * FROM users WHERE id BETWEEN ? AND ?', [15,48]);

OR by using an Eloquent model as follow

\App\User::whereBetween('id', array(15, 48))->get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM