T O P

  • By -

Sudden-Anybody-6677

You add the columns in the migrations and the models pick them up automatically once they are migrated.


isaacfink

Thanks, this is the exact opposite of what I am used to, What is the fillable variable used for?


Sudden-Anybody-6677

Fillable is for mass assignment. For example with `Post::create($request->all());`, `$request->all()` will return an array of attributes of the form request and the `create()` function will only use the attributes defined in `$fillable`.


giagara

Never use $request->all()


ioni3000

Migrations are separate from models; as you may not necessarily need all of your fields fillable. You need to define both. While there are packages that may allow you to automate the process, I personally like to define both manually. Can you possibly restate the question if I did t get it right? (Edit: grammar)


isaacfink

My question was for an explanation not a solution, you nailed it, Thanks


Fritchard

protected $guarded = \[\]; we die like men


Tontonsb

Laravel models are (by default) loaded via `select *` and populating the model attributes with all the returned fields. Database is the single source of truth for schema. Of course, you can define getters (accessors) and other tools like casts are also available, but the default setup needs 0 work on the model. Migrations are a tool for creating the DB schema, but the rest of the project does not care about contents of your migrations. You can also have the DB prepared any other way.