Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Attribute Reader Laravel Package

spatie/php-attribute-reader

Lightweight PHP 8+ utility to read native attributes from classes, methods, properties, and parameters using reflection. Designed for simple, fast attribute discovery in frameworks and libraries, with an API that fits common annotation-style workflows.

View on GitHub
Deep Wiki
Context7

title: Introduction weight: 1

PHP 8.0 introduced attributes, a way to add structured metadata to classes, methods, properties, constants, parameters, and functions. The idea is great, but the reflection API to read them is verbose.

Imagine you have a controller with a Route attribute:

#[Route('/my-controller')]
class MyController
{
    // ...
}

Getting that attribute instance using native PHP requires this:

$reflection = new ReflectionClass(MyController::class);
$attributes = $reflection->getAttributes(Route::class, ReflectionAttribute::IS_INSTANCEOF);

if (count($attributes) > 0) {
    $route = $attributes[0]->newInstance();
}

With this package, it becomes a single call:

use Spatie\Attributes\Attributes;

$route = Attributes::get(MyController::class, Route::class);

The package handles instantiation, IS_INSTANCEOF matching, and returns null for missing targets instead of throwing exceptions.

It works on all attribute targets: classes, methods, properties, constants, parameters, and functions. It supports repeatable attributes and can discover all usages of an attribute across an entire class.

We got badges

Latest Version on Packagist Tests

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport