Models

Fillable vs Guarded

  • Use the guarded property to specify which attributes are not mass assignable.
class User extends Model
{
    protected $guarded = [
        'id',
        'password'
    ];
}

Casting

  • Use the casts property to cast attributes to native types.
class User extends Model
{
    protected $casts = [
        'is_admin' => 'boolean',
        'age'      => 'integer',
        'meta'     => 'array',
    ];
}

Factories

  • All models should have a factory
  • Use factories to generate test data

Seeders

  • Use seeders to populate the database with test data where necessary
  • Use seeders to populate the database with static data where necessary
Previous
Home
Next
Routes