Laravel: Retrieve Fillable Attributes on a Model

If you ever need to get the fillable properties from one of your Eloquent models in Laravel 4, there is an easy way to get it.

$myModel->getFillable();

This can be useful if you if you are trying to dynamically generate a "Create" form in a Blade template for the Eloquent model.

@foreach($myModal->getFillable() as $property)
   {{ Form::label($property, ucwords($property)) }}
   {{ Form::text($property) }}
@endforeach

Or, if you are using Bootstrap

@foreach($myModal->getFillable() as $property)
    
{{ Form::label($property, ucwords($property)) }} {{ Form::text($property, null, ['class' => 'form-control']) }}
@endforeach

Small dog web development studio
View All Our Posts

Web application developers in western Washington, creating user centric web solutions for businesses of all shapes and sizes.

Our projects include ecommerce, event organization, user driven web applications and more.


Small Dog Studios, LLC. Small Dog Studios News