If you query all results with ->all()
or ->get()
, you may then perform various Collection operations on the same result, it won’t query database every time.
1$users = User::all();2echo 'Max ID: ' . $users->max('id');3echo 'Average age: ' . $users->avg('age');4echo 'Total budget: ' . $users->sum('budget');