1DistrictModel::insert([
2 'code' => $data->code,
3 'name' => $data->name,
4 'region_id' => $data->region_id,
5 'sorting' => $data->sorting,
6 ]);
1DB::table('users')->insert([
2 'email' => 'kayla@example.com',
3 'votes' => 0
4]);
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// 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);
1$flight = App\Models\Flight::find(1);
2
3$flight->name = 'New Flight Name';
4
5$flight->save();