Eloquent: Collections
Eloquent: Collections
Introduction
All multi-result sets returned by Eloquent are an instance of the Illuminate\Database\Eloquent\Collection
object, including results retrieved via the get
method or accessed via a relationship. The Eloquent collection object extends the Laravel base collection, so it naturally inherits dozens of methods used to fluently work with the underlying array of Eloquent models.
Of course, all collections also serve as iterators, allowing you to loop over them as if they were simple PHP arrays:
$users = App\User::where('active', 1)->get(); foreach ($users as $user) { echo $user->name; }
H