← Back to list

Laravel 13: Attributes List

For years, Laravel developers have been tethered to “the old way”: a wall of protected class properties like $fillable, $table, and…

Sandro Jhuliano Cagara · 2026-04-18 15:01 · 1 claps · 3.4 min read
#laravel-13 #php-attributes #php
Open on Medium ↗

Laravel 13: Attributes List

For years, Laravel developers have been tethered to “the old way”: a wall of protected class properties like $fillable, $table, and $connection. While functional, these properties often feel like boilerplate cluttering the top of your Eloquent models.

With PHP 8 and Laravel 11+, the framework has fully embraced Native Attributes. This shift provides a cleaner, more expressive, and highly declarative way to annotate your classes. Instead of defining behavior inside the class body, you declare your intent directly above the class or method definition.

Here is the complete, exhaustive list of every attribute Laravel currently ships with, organized by domain.

📊 Eloquent Models

Eloquent sees the most significant quality-of-life improvements. Your model’s behavior is now declared as metadata at the very top.

  • **#[Table]**: Set the database table name.
  • **#[Fillable]**: Define mass-assignable attributes.
  • **#[Guarded]**: Define guarded attributes.
  • **#[Hidden]**: Hide from JSON serialization.
  • **#[Visible]**: Define visible attributes.
  • **#[Appends]**: Append accessors to array/JSON output.
  • **#[Touches]**: Automatically update the updated_at timestamp on related models.
  • **#[Connection]**: Specify the database connection for the model.
  • **#[Unguarded]**: Disable mass assignment protection for the model.
  • **#[CollectedBy]**: Define a custom collection class for model results.
  • **#[WithoutTimestamps]**: Disable created_at and updated_at.
  • **#[WithoutIncrementing]**: Indicate the ID is not an auto-incrementing integer.
  • **#[ScopedBy]**: Apply global scopes to the model.
  • **#[ObservedBy]**: Register model observers directly.
  • **#[DateFormat]**: Define the storage format for timestamps.
  • **#[Scope]**: Mark a method as a local query scope.
  • **#[Boot]**: Hook into the trait's model boot logic.
  • **#[Initialize]**: Hook into the trait's model initialization.
  • **#[UseEloquentBuilder]**: Specify a custom Query Builder class.
  • **#[UseFactory]**: Specify the factory class for the model.
  • **#[UsePolicy]**: Explicitly link the model to a Policy.
  • **#[UseResource]**: Link the model to an API Resource.
  • **#[UseResourceCollection]**: Link the model to a Resource Collection.

📦 Queues, Jobs & Listeners

Configure retry logic and execution behavior without touching a constructor or method body.

  • **#[Connection]**: Define the queue connection.
  • **#[Queue]**: Define the specific queue name.
  • **#[Delay]**: Delay the job execution.
  • **#[Backoff]**: Configure the retry delay strategy.
  • **#[Tries]**: Set maximum retry attempts.
  • **#[Timeout]**: Set the job timeout duration.
  • **#[UniqueFor]**: Set the duration for unique job locks.
  • **#[DeleteWhenMissingModels]**: Automatically delete the job if models are missing.
  • **#[FailOnTimeout]**: Mark the job as failed if it times out.
  • **#[MaxExceptions]**: Set the maximum number of unhandled exceptions allowed.
  • **#[WithoutRelations]**: Prevent Eloquent relations from being serialized.
  • **#[DebounceFor]**: Debounce the job execution for a specified window.

⚙️ Console Commands

Artisan commands no longer need a wall of class properties. Everything from the signature to the help text can live as an attribute.

  • **#[Signature]**: Define the command signature (e.g., app:sync {user}).
  • **#[Description]**: Define the command description.
  • **#[Aliases]**: Define alternative names for the command.
  • **#[Usage]**: Provide additional usage examples.
  • **#[Help]**: Define the detailed help text.
  • **#[Hidden]**: Hide the command from the Artisan list.

🎛️ Controllers

Middleware and authorization move out of __construct() and sit directly above the methods they apply to.

  • **#[Middleware]**: Assign middleware to the entire class or specific methods.
  • **#[Authorize]**: Authorize the request via a Gate or Policy check.

🧪 Form Requests

Validation behavior and error handling are now declarable without overriding methods.

  • **#[RedirectTo]**: Specify the path to redirect to on validation failure.
  • **#[RedirectToRoute]**: Specify the route name for redirection.
  • **#[StopOnFirstFailure]**: Stop validation after the first error is found.
  • **#[ErrorBag]**: Define a custom name for the error bag.
  • **#[FailOnUnknownFields]**: Throw an error if fields not in the rules are present.

🌱 Testing & Factories

Control your test environment and link models to factories with zero guesswork.

  • **#[Seeder]**: Run a specific seeder class for the test.
  • **#[Seed]**: Run the default database seeder for the test.
  • **#[SetUp]**: Define a trait-based setup hook.
  • **#[TearDown]**: Define a trait-based teardown hook.
  • **#[UnitTest]**: Flag a test to skip the full framework boot.
  • **#[UseModel]**: Define the model associated with a factory.

📡 API Resources

Control how resources are collected and whether array keys are preserved during transformation.

  • **#[Collects]**: Define the resource collection mapping.
  • **#[PreserveKeys]**: Preserve keys in the resource output.

🔌 Dependency Injection

This is where attributes really shine. Constructor injection gets a major upgrade — inject values by name, not just by type-hint.

  • **#[Auth]**: Inject a specific auth guard instance.
  • **#[Authenticated]**: Inject the currently authenticated user.
  • **#[Bind]**: Apply a contextual binding to an implementation.
  • **#[Cache]**: Inject a specific cache store instance.
  • **#[Config]**: Inject a specific configuration value (e.g., #[Config('app.name')]).
  • **#[Context]**: Inject data from the application context.
  • **#[CurrentUser]**: Inject the authenticated user model.
  • **#[DB]**: Inject a database connection.
  • **#[Database]**: Inject a specifically named DB connection.
  • **#[Give]**: Provide a specific binding contextually.
  • **#[Log]**: Inject a named logger channel.
  • **#[RouteParameter]**: Inject a specific value from the current route.
  • **#[Scoped]**: Register the class as a scoped singleton.
  • **#[Singleton]**: Register the class as a singleton.
  • **#[Storage]**: Inject a specific storage disk instance (e.g., #[Storage('s3')]).
  • **#[Tag]**: Inject all bindings associated with a specific tag.

The Verdict: A Modern Standard

Attributes are purely additive. Your existing code will still work, but adopting these makes your codebase feel significantly more modern and easier to read.

Requirements: PHP 8.0+ and Laravel 11.0+. Ready to clean up your code? Start by refactoring your most cluttered model today.


메타데이터
post_id
463dbd003e2c
slug
laravel-13-attributes-463dbd003e2c
url
https://medium.com/@sandrojhulianocagara/laravel-13-attributes-463dbd003e2c
canonical_url
https://medium.com/@sandrojhulianocagara/laravel-13-attributes-463dbd003e2c
author_url
https://medium.com/@sandrojhulianocagara
status
ok
fetched_at
2026-06-09 15:37:30