laravel get first code example
Example 1: laravel get first record
'First email'
User::whereEmail($email)->first();
'First Record'
User::first();
Example 2: laravel eloquent get first
$user = App\User::where('id',$id)->first();
$userId = App\User::where(...)->pluck('id');
Example 3: laravel 8 orderby
$flights = App\Models\Flight::where('active', 1)
->orderBy('name', 'desc')
->take(10)
->get();
Example 4: laravel find query
$flight = App\Models\Flight::find(1);
$flight = App\Models\Flight::where('active', 1)->first();
$flight = App\Models\Flight::firstWhere('active', 1);
Example 5: laravel find query
foreach (Flight::where('foo', 'bar')->cursor() as $flight) {
}