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
Enhanced Resources

Enhanced Resources Laravel Package

sourcetoad/enhanced-resources

Laravel API resource enhancement that lets a single Resource expose multiple output “formats” via PHP attributes. Mark methods with #[Format], pick formats with ->format('name'), and optionally set a default with #[IsDefault] to avoid exceptions.

View on GitHub
Deep Wiki
Context7

Laravel's API Resources enhanced.

Frequently asked questions about Enhanced Resources
How do I install Enhanced Resources in a Laravel 13.x project?
Run `composer require sourcetoad/enhanced-resources` in your project directory. The package is officially compatible with Laravel 13.x and PHP 8.3+, so no additional configuration is needed beyond the installation.
Can I use this package with Laravel 10.x or older versions?
The package is optimized for Laravel 13.x and PHP 8.3+, but it may work with older versions. However, no long-term support is guaranteed for Laravel <10.x, so test thoroughly if you must use it there.
How do I define multiple formats for a single API Resource?
Use the `#[Format]` attribute on each method representing a format. For example, methods `foo()` and `bar()` will create formats named `foo` and `bar`. Call them explicitly with `->format('foo')` or set a default with `#[IsDefault]`.
What happens if I don’t specify a format and there’s no default?
The package throws a `NoFormatSelectedException`. To avoid this, always define a default format using `#[IsDefault]` on one of your `#[Format]` methods, or explicitly specify the format when resolving the resource.
Does this package work with Laravel Octane or real-time APIs?
Yes, Enhanced Resources integrates seamlessly with Laravel Octane and real-time APIs. Use it to dynamically structure WebSocket payloads or Event Bus messages by leveraging multiple formats for different client needs.
Will this package slow down my API responses in Laravel 13?
Laravel 13’s optimizations (OpCache, JIT, and service container improvements) should mitigate overhead. Profile with tools like Laravel Telescope or Blackfire to measure performance, especially for nested relationships.
Can I use this with Laravel Livewire or Inertia.js?
Yes, Enhanced Resources works with Livewire and Inertia.js since they both rely on Laravel’s API Resources under the hood. Use it to customize payloads for different frontend states or client-side logic.
How do I test Enhanced Resources in Laravel 13 with Pest?
Use Pest 2.0’s live assertions to validate payloads. For example, test format outputs with `assertJson($resource->format('foo'))` or snapshot testing for complex responses. Laravel 13’s new testing helpers simplify this process.
Are there alternatives to Enhanced Resources for dynamic API payloads?
Alternatives include custom resource classes with conditional logic, Laravel’s built-in `JsonResource`, or packages like `spatie/array-to-object`. However, Enhanced Resources provides a cleaner, attribute-driven approach for managing multiple formats without manual switching.
How do I debug issues with nested relationships in Enhanced Resources?
Use Laravel Telescope 5.0+ to log queries and identify N+1 issues. Enable query logging in `config/telescope.php` and check for inefficient nested eager loading in your format methods.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky