Don't forget the fillables!

Just a quick tip. I've noticed a really typical mistake by developers, which caused some headache for myself and for others - you add a new field into the database table, but for some reason it isn't automatically saved. The full situation - you've added a field into a database, made and run a migration for that, and then just add it to the form. Of course, Laravel should take care of it with Model::create($request->all()), right? But sometimes it doesn't. Because you forget to add a new field to the $fillable array. In the Eloquent models there's an array which defines what fields are automatically filled with create() method:
protected $fillable = ['first_name', 'last_name', 'email'];
So, for example, if you add a new field address to this table, please don't forget to add it to $fillable array - otherwise it won't be saved. The worst part is that Laravel won't throw any error - it would just save the row without that column value. As I said - just a quick tip. Hope that helps!

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month

Written by