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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope