All Laravel PHP Attributes at Your Disposal
PHP attributes are a great way to add metadata to your classes, methods, and properties. Laravel provides a bunch of them out of the box, you can use in your applications.
Stage 1Observed By
The ObservedBy attribute allows you to define an observer for a model. This is a great way to keep your model clean and move the observer logic to a separate class.
Stage 2Scoped By
The ScopedBy attribute allows you to define a global scope for a model. This is a handy way to apply common query constraints to a model.
Stage 3Contextual Attributes
Laravel provides a convenient way to handle dependency injection for specific contexts, such as injecting driver implementations or configuration values. Instead of manually setting up contextual bindings in service providers, Laravel offers a range of contextual binding attributes. These attributes streamline the process of injecting context-specific values.
Take a look at the following examples:
Laravel even lets you inject the current User to a route:
Stage 4Delete When Missing Models
When injecting models into your jobs, you can use the DeleteWhenMissingModels attribute to automatically delete the job if the injected model is missing from the database.
Stage 5Without Relations
The WithoutRelations attribute allows you to load a model without its relationships. This can be useful when you want to avoid loading unnecessary data.
Stage 6Custom Eloquent Collections
When you query a model, Eloquent returns a collection of models through Laravel's base Collection class. Sometimes you prefer to use a custom collection class where you can define additional methods or override existing ones. You can achieve this by using the CollectedBy attribute.
Did I Miss Any?
If you know any other Laravel PHP attributes, please let me know on Twitter or send a PR on GitHub. I would love to add them to this list.
My Mind Has Been Blown By Tech, And Now It IS About AI
AIJan 31, 2026