or in laravel eloquent 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 delete where
DB::table('users')->where('id', $id)->delete();
Example 3: larave Soft Deletes
Schema::table('flights', function (Blueprint $table) {
$table->softDeletes();
});
Example 4: eloquent first
$user = User::where('mobile', Input::get('mobile'))->get();
if (!$user->isEmpty()){
$firstUser = $user->first()
}
Example 5: laravel find query
$model = App\Models\Flight::where('legs', '>', 100)->firstOr(function () {
// ...
});
Example 6: laravel find query
<?php
$flights = App\Models\Flight::all();
foreach ($flights as $flight) {
echo $flight->name;
}