stack
stack

Reputation: 10218

How can I select all table's rows?

I need to get all rows of the table. Currently I do that like this:

$all_rows = TBname::where('id', '>', '0')->get();

As you see, I've used id > 0 condition to select all rows. But I think this isn't a standard way. In pure SQL I can use . . . where 1. But in Laravel where('1') doesn't work.

Anyway, what's the most standard approach to select (and fetch) all rows in Laravel?

Upvotes: 1

Views: 91

Answers (2)

S.I.
S.I.

Reputation: 3375

With ->all()

$all_rows = TBname::all();

More information in Eloquent Retrieving Models

Upvotes: 1

Alexey Mezenin
Alexey Mezenin

Reputation: 163758

Use all():

TBname::all();

Or get():

TBname::get();

Upvotes: 5

Related Questions