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.
so its okay to stick with $users = User::all(); than $users = DB::table('users')->get() since its short code
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.
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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community