Laravel Eloquent: Retrieving Models

<?php

$flights = App\Flight::all();

foreach ($flights as $flight) {
    echo $flight->name;
}

Adding Additional Constraints

$flights = App\Flight::where('active', 1)
               ->orderBy('name', 'desc')
               ->take(10)
               ->get();

Refreshing Models

$flight = App\Flight::where('number', 'FR 900')->first();

$freshFlight = $flight->fresh();
$flight = App\Flight::where('number', 'FR 900')->first();

$flight->number = 'FR 456';

$flight->refresh();

$flight->number; // "FR 900"

Collections

$flights = $flights->reject(function ($flight) {
    return $flight->cancelled;
});
Foreach ($flights as $flight) {
    echo $flight->name;
}

Laravel Eloquent: Retrieving Models — Structure map

Clickable & Draggable!

Laravel Eloquent: Retrieving Models — Related pages: