1# The easiest way to create a model instance is using the
2# make:model Artisan command:
3
4php artisan make:model Flight
5
6# If you would like to generate a database migration when you
7# generate the model, you may use the --migration or -m option:
8
9php artisan make:model Flight --migration
10php artisan make:model Flight -m
1$user = User::updateOrCreate(['name' => request()->name], [
2 'foo' => request()->foo
3]);
4
1// If there's a flight from Oakland to San Diego, set the price to $99.
2// If no matching model exists, create one.
3$flight = App\Models\Flight::updateOrCreate(
4 ['departure' => 'Oakland', 'destination' => 'San Diego'],
5 ['price' => 99, 'discounted' => 1]
6);
1use App\Models\Flight;
2
3$flight = Flight::find(1);
4
5$flight->name = 'Paris to London';
6
7$flight->save();
1$flight = App\Models\Flight::find(1);
2
3$flight->name = 'New Flight Name';
4
5$flight->save();