Summer sale! Save 50% on access to our entire library of courses.Join here →

Get the fillable array from a Laravel model

July 5th, 2024

If, for any reason, you need to get the fillable fields from a Laravel model, it's pretty straightforward.

Here's the first way you're able to achieve this:

$model = new User();

This returns an array of all the fillable columns.

But we can do better. You can inline it like this:

dd((new User)->getFillable());

And from PHP 8.4, you won't need to parenthesize the instantiation of the model, so you'll be able to do this:

dd(new User()->getFillable());

Perhaps a neater solution is resolving the model out of the container first. Here's what that looks like:


So, there are a bunch of ways to get the fillable columns you've defined in your models — all these examples do the same thing. Just choose which fits your style best.

Thanks for reading! If you found this article helpful, you might enjoy our practical screencasts too.
Alex Garrett-Smith
Share :


No comments, yet. Be the first to leave a comment.

Tagged under