-1

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

Mtxz
  • 3,749
  • 15
  • 29
SnYpe
  • 15
  • 3

1 Answers1

1

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.

Mtxz
  • 3,749
  • 15
  • 29
  • 1
    My pleasure, please consider accepting my post as the answer if it suits you. Still, for a simple query like yours, a quick google search about "Laravel limit query" would have been enough :) – Mtxz Sep 21 '21 at 02:27