LoginSignup
0
0

More than 1 year has passed since last update.

[Laravel 8] Eloquent Modelのfillableとguarded

Posted at

It is necessary to specify either a fillable or guarded property on your model class. These properties are required because all Eloquent models are protected against mass assignment vulnerabilities by default.

$fillable

To get started, you should define which model attributes you want to make mass assignable. You may do this using the $fillable property on the model.

Models\Student.php
protected $fillable = ['first_name','last_name'];

$guarded

If you would like to make all of your attributes mass assignable, you may define your model's $guarded property as an empty array.

Models\Student.php
protected $guarded = [];

Reference:
https://laravel.com/docs/8.x/eloquent#mass-assignment

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0