Home > Blockchain >  Fetch only few data from database in Laravel
Fetch only few data from database in Laravel

Time:09-21

I want to fetch only 4 rows from my database's table.

$data=table::all();

Returns all data/rows from my table. How can I get only 4 rows instead of all?

Thanks

CodePudding user response:

Try $data=table::take(4); that will only retrieve the 4 first records.

You also have the limit() method. See details in the Laravel Limit & Offset docs.

  • Related