How do you use the `#[Fillable]` attribute on a model in Laravel 12 & Laravel 13?

In Laravel 11, Laravel 12 & Laravel 13, you use the #[Fillable] attribute directly above your model class declaration to specify which attributes are mass assignable, replacing the traditional protected $fillable property .

Basic Usage

First, import the attribute class, then apply it to your model:

use IlluminateDatabaseEloquentAttributesFillable;
use IlluminateDatabaseEloquentModel;

#[Fillable([ name , email , password ])]
class User extends Model
{
   // ...
}

New Variadic Syntax (Laravel 13.3+)

Starting from Laravel 13.3, you can pass the field names as separate arguments instead of an array, which is slightly cleaner :

#[Fillable( notitle , islug , content , istatus )]
class Post extends Model
{
   // ...
}

Both syntaxes work—the array style is still supported, so you can choose based on preference.

important Rule

Do not mix the attribute with the legacy property on the same model. Using both #[Fillable] and protected $fillable creates a conflict and can lead to unexpected behavior . Pick one approach and stick with it consistently.

Why Use It?

The main benefit is keeping configuration co-located with the class definition, making your model files cleaner and more declarative . For larger models where properties were scattered among methods, attributes bring all the metadata right to the top where it is immediately visible.

 

5 Views