# Create a new Drink model.
php artisan make:model Drink
#create model
php artisan make:model Model_Name
#create model with migration
php artisan make:model Model_Name -m
#create model with migration and controller
php artisan make:model Model_Name -mcr
// Model Naming Convention: singular, ProperCase EG: User, UserRequest
php artisan make:model Flight -f // with Factory
php artisan make:model Flight -s // with Seeder
php artisan make:model Flight -c // with Controller
php artisan make:model Flight -m // with Migration
// EG: use any flag combo to create Model with Migration, Factory, Seeder and Controller
php artisan make:model Flight -mfsc
php artisan make:model ModelName
$user = User::create([
'first_name' => 'Taylor',
'last_name' => 'Otwell',
'title' => 'Developer',
]);
$user->title = 'Painter';
$user->isDirty(); // true
$user->isDirty('title'); // true
$user->isDirty('first_name'); // false
$user->isClean(); // false
$user->isClean('title'); // false
$user->isClean('first_name'); // true
$user->save();
$user->isDirty(); // false
$user->isClean(); // true
## https://laravel.com/docs/eloquent#chunking-results
use AppModelsFlight;
Flight::chunk(200, function ($flights) {
foreach ($flights as $flight) {
//
}
});
php artisan make:model Flight --factory
php artisan make:model Flight -f
php artisan make:model Flight --seed
php artisan make:model Flight -s
php artisan make:model Flight --controller
php artisan make:model Flight -c
php artisan make:model Flight -mfsc
//Generate model with migration, factory, seeder, and controller
php artisan make:model Post -mfsc
php artisan make:model Model -mf
// -mf creates the factory and migration
php artisan make:model Task -mcrR
<?php
namespace AppModels;
use IlluminateDatabaseEloquentBuilder;
use IlluminateDatabaseEloquentModel;
class User extends Model
{
/**
* The "booted" method of the model.
*
* @return void
*/
protected static function booted()
{
static::addGlobalScope('age', function (Builder $builder) {
$builder->where('age', '>', 200);
});
}
}