Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 1 year ago.
0

It depends what you need. User::all() will give you a collection of User models. DB::table('users')->get() would give you an array of stdClass objects.

Both methods use query builder to build the queries.

0

so its okay to stick with $users = User::all(); than $users = DB::table('users')->get() since its short code

0

Probably DB::table('users')->get() would be a little faster since it omits all the Model logic (mutators and such) but then again - that logic is there for a reason. For simple queries like that I'd use the Model call, if I need more complex queries (joins and such) I'd use the DB:: call.

0

stick to just one and be consistent.. thats more important, also try to give column names so you are not fetching everything! would be the second tip

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.