Skip to content
Advertisement

How to get n data from table in laravel controller?

I want to get only 5 data from user table

I try to write User::where("","")->get(5); but seems not working.

Advertisement

Answer

Use instead:

User::query()->take(5)->get();

Or if with where condition:

User::query()->where("column", "value")->take(5)->get();
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement