laravel where and find code example
Example 1: find or fail laravel
$model = App\Models\Flight::findOrFail(1);
$model = App\Models\Flight::where('legs', '>', 100)->firstOrFail();
Example 2: laravel find by
$flight = App\Flight::find(1);
$flight = App\Flight::where('active', 1)->first();
$flight = App\Flight::firstWhere('active', 1);
Example 3: laravel where
$users = DB::table('users')
->whereMonth('created_at', '12')
->get();
Example 4: laravel where
$users = DB::table('users')
->whereDate('created_at', '2016-12-31')
->get();
Example 5: laravel update first
Model::where(['x' => 1, 'y' => 2])->first()->update([...]);