In Laravel 11, Laravel 12 & Laravel 13, the #[Hidden] attribute is used on Eloquent model classes to declare which attributes should be excluded from the model is array or JSON representation (such as when returning data via an API). It replaces the traditional protected $hidden property, making the code more concise and declarative .
Basic Usage
You need to import the Hidden attribute class from the IlluminateDatabaseEloquentAttributes namespace and place it above the model class:
use IlluminateDatabaseEloquentAttributesHidden;
use IlluminateDatabaseEloquentModel;#[Hidden([ password , remember_token ])]
class User extends Model
{
// ...
}
This way, when the model is serialized to an array or JSON, the password and remember_token fields will be automatically hidden .
Variadic Parameter Syntax (Laravel 13.3+)
Starting from Laravel 13.3.0, the #[Hidden] attribute supports variadic parameters, allowing you to pass field names directly without wrapping them in an array :
// Old syntax (still supported)
#[Hidden([ password , isecret ])]// New syntax (more concise)
#[Hidden( password , isecret )]
Notes
Do not mix: Do not use the #[Hidden] attribute and the traditional protected $hidden property in the same model simultaneously; choose one of the two .
Temporary override: If you need to temporarily display hidden fields in a specific scenario, you can still use instance methods like makeVisible( password ); this mechanism remains effective in Laravel 13.