Weave 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
Laravel Decorator

Laravel Decorator Laravel Package

imanghafoori/laravel-decorator

Laravel Decorator lets you wrap method calls on any class with custom decorators, adding caching, logging, retries, or auth checks without editing the original code. Register a decorator once and every call to that class flows through it.

View on GitHub
Deep Wiki
Context7

Easily decorate your method calls with laravel-decorator package

Frequently asked questions about Laravel Decorator
What is imanghafoori/laravel-decorator used for?
Laravel Decorator lets you wrap method calls on any class with custom decorators so you can add caching, logging, retries, fallback values, or auth checks without editing the original class. It applies the decorator pattern at the call site rather than through dependency injection, typically using a global decorate() helper with a callable or a Class@method string. It is a good fit for adding cross-cutting behavior to an existing service or repository layer without creating new interfaces and bindings for every case.
How do I install laravel-decorator in a Laravel application?
Install it with Composer using composer require imanghafoori/laravel-decorator. The package uses Laravel package discovery and does not require schema changes, migrations, or config publication for basic use. A working proof-of-concept is typically small, but you should still review the source and confirm the Composer constraints match your Laravel and PHP versions.
How do I decorate a method call with laravel-decorator?
You typically wrap a callable or a Class@method string with the package's decorate() helper and a decorator that defines the cross-cutting behavior. Register the decorator once and calls routed through that wrapper flow through it. Because the target can be a string like App\Services\Foo@bar, the call site is not visible to IDEs or Larastan, so renaming methods requires manual updates.
Can laravel-decorator add caching to a method without changing the class?
Yes, the package is designed to add caching or memoization around method calls without changing the decorated class's signature. However, cache correctness depends on how the caching decorator derives keys from the target and its arguments. You should read the source to verify how non-scalar arguments are serialized and whether argument order is handled, because shallow key derivation can cause silent cache collisions.
Does laravel-decorator support Laravel 10, 11, and 12?
The provided assessment does not confirm a verified compatibility matrix for Laravel 10, 11, or 12, so you should check the package's composer.json constraints and CI status before adopting it. The last release noted is April 2024, which means you need to verify that the constraints do not block your next framework upgrade. Test against your target PHP versions, such as 8.2, 8.3, or 8.4, as part of the proof-of-concept.
How does laravel-decorator handle cache keys and non-scalar arguments?
The exact cache-key derivation algorithm is not specified in the provided context, and the assessment warns that it must be verified by reading the source rather than relying on the README. If key derivation is shallow, such as string-casting objects or ignoring argument order, you can get silent cache collisions. Before production use, audit how the caching decorator serializes arrays and objects and whether it provides stampede protection on cold or expired keys.
Is laravel-decorator safe to use with Laravel Octane and queue workers?
Decorator registries or memoization stores held in static state can leak across tests and may persist across requests in Octane or long-running queue workers. The provided assessment does not confirm an Octane or queue-worker reset hook, so you should verify this in the source. If memoized state is per-process, ensure there is a reset mechanism to prevent unbounded growth and cross-job contamination.
What are the alternatives to laravel-decorator?
Laravel's built-in Cache::remember covers many short-lived caching use cases without an extra package. For stricter architectures, you can use dependency-injection-based decorators with interfaces and container bindings, or write small hand-written decorator classes. Laravel Decorator is most useful when you want call-site decoration with minimal interface churn, but it overlaps functionally with Cache::remember and should be used consistently.
How do I test code that uses the decorate() helper?
The global decorate() helper sits outside the container and is invisible to static analysis, so it can be harder to mock than an injected dependency. Prefer integration tests that exercise the decorated call path and verify caching, fallback, and retry behavior. Also clear any static decorator or memoization state between tests to avoid order-dependent failures.
Is laravel-decorator actively maintained and safe for production?
The assessment notes 139 stars, zero dependent packages, a single maintainer, and a last release in April 2024, so treat it as a replaceable leaf utility rather than a foundational dependency. The codebase is small and MIT-licensed, which makes vendoring or forking the handful of source files realistic. For production, require explicit logging or metrics on any fallback path, verify cache-key behavior, and assign an internal owner willing to fork if needed.
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.
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator