laravel create model from table code example

Example 1: laravel model tablename

protected $table = 'DomainRelatedSettings';

Example 2: how to create model in laravel

php artisan make:model Flight

Example 3: laravel create model and migration

# If you would like to generate a database migration when you 
# generate the model, you may use the --migration or -m option:

php artisan make:model Flight --migration
php artisan make:model Flight -m

Example 4: laravel update

<!-mass update-->
App\Models\Flight::where('active', 1)
          ->where('destination', 'San Diego')
          ->update(['delayed' => 1]);

Example 5: laravel model::query

// Eloquent's Model::query() returns the query builder

Model::where()->get();
// Is the same as 
Model::query()->where()->get();

Model::query();
// Can be useful to add query conditions based on certain requirements

// See https://stackoverflow.com/questions/51517203/what-is-the-meaning-of-eloquents-modelquery

Example 6: laravel find query

<?php

$flights = App\Models\Flight::all();

foreach ($flights as $flight) {
    echo $flight->name;
}

Tags:

Sql Example