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 /**
2 * The attributes that are mass assignable.
3 */
4 protected $fillable = [
5 'title',
6 'slug',
7 'body',
8 'image',
9 'published',
10 'comments_open'
11 ];
1class User extends Model {
2
3 public function scopePopular($query)
4 {
5 return $query->where('votes', '>', 100);
6 }
7
8 public function scopeWomen($query)
9 {
10 return $query->whereGender('W');
11 }
12
13}
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);
1public function apply(Builder $builder, Model $model)
2 {
3 $builder->where('age', '>', 200);
4 }