Skip to main content
Tutorial Free

Don't forget the fillables!

June 26, 2015
1 min read
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!

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.