PHPackages                             benyaminrmb/laravel-dynamic-resources - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. benyaminrmb/laravel-dynamic-resources

ActiveLibrary[API Development](/categories/api)

benyaminrmb/laravel-dynamic-resources
=====================================

Dynamic API resources with mode-based field selection for Laravel. Define minimal, default, detailed modes and compose them on the fly.

v0.1.5(1y ago)152MITPHPPHP ^8.2CI failing

Since Nov 16Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Benyaminrmb/laravel-dynamic-resources)[ Packagist](https://packagist.org/packages/benyaminrmb/laravel-dynamic-resources)[ RSS](/packages/benyaminrmb-laravel-dynamic-resources/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (11)Used By (0)

Laravel Dynamic Resources v2
============================

[](#laravel-dynamic-resources-v2)

[![Latest Version on Packagist](https://camo.githubusercontent.com/61c715ab9da5ec86f06a682f83c58c0b6d2e30721132cd00a7e6a94005708cb6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62656e79616d696e726d622f6c61726176656c2d64796e616d69632d7265736f75726365732e737667)](https://packagist.org/packages/benyaminrmb/laravel-dynamic-resources)[![Total Downloads](https://camo.githubusercontent.com/04ad422046f143aceae59ad7f642652ad05355038c0be8dcb62ed66f34fc74f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62656e79616d696e726d622f6c61726176656c2d64796e616d69632d7265736f75726365732e737667)](https://packagist.org/packages/benyaminrmb/laravel-dynamic-resources)[![Tests](https://github.com/benyaminrmb/laravel-dynamic-resources/actions/workflows/test.yml/badge.svg)](https://github.com/benyaminrmb/laravel-dynamic-resources/actions)[![PHPStan](https://camo.githubusercontent.com/1bc07920f0d36e55c17e1d38b1caa132cc605f51a82b388c962870b9a747b898/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e737667)](https://phpstan.org/)

**Dynamic API resources with mode-based field selection for Laravel.** Define minimal, default, detailed modes and compose them on the fly. Reduce API payload sizes, improve performance, and give clients control over response structure.

Features
--------

[](#features)

- **Mode-based field selection** - Define `minimal`, `default`, `detailed` modes and switch between them
- **Composable modes** - Combine modes with `->withAvatar()->withPosts()`
- **Field filtering** - Fine-grained control with `only()` and `except()`
- **Nested resource support** - Mode inheritance through resource trees
- **Request-based selection** - Let clients choose modes via query params: `?mode=minimal&fields=id,name`
- **PHP Attributes** - Modern declarative syntax with `#[Field]` and `#[Mode]` attributes
- **Artisan commands** - `make:dynamic-resource` and `resource:list`
- **Strict type safety** - PHP 8.4, PHPStan level 9

Requirements
------------

[](#requirements)

- PHP 8.4+
- Laravel 11.0+ or 12.0+

Installation
------------

[](#installation)

```
composer require benyaminrmb/laravel-dynamic-resources
```

Publish the config (optional):

```
php artisan vendor:publish --tag=dynamic-resources-config
```

Quick Start
-----------

[](#quick-start)

### 1. Create a Resource

[](#1-create-a-resource)

```
php artisan make:dynamic-resource UserResource --model=User
```

Or create manually:

```
