code20 / laravel-api-resource
Scaffold a full API layer (Form Request, API Resource, Service, Controller, and optional Policy/DTO/Exception/Pest tests) for Laravel with a single artisan command.
v1.0.1
2026-08-31 21:37 UTC
Requires
- php: ^8.1
- illuminate/console: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
README
Scaffold a full API layer - Form Request, API Resource, Service, Controller,
and optionally a Policy, DTO, conflict Exception, and Pest tests - from a
single artisan command.
Installation
composer require code20/laravel-api-resource
Once published to Packagist, that second step is all a consumer needs to run
- Laravel's package auto-discovery registers the service provider and the
make:api-resourcecommand automatically. Nothing to add toconfig/app.php.
Publishing config/stubs (optional)
The package works out of the box with its bundled stubs and defaults. To customize either:
# config/api-boilerplate.php php artisan vendor:publish --tag=api-boilerplate-config # stubs/api-boilerplate/*.stub php artisan vendor:publish --tag=api-boilerplate-stubs # both php artisan vendor:publish --tag=api-boilerplate
If a stub isn't published (or you delete a published one), the command transparently falls back to the version bundled inside the package — nothing breaks either way.
Usage
# Single resource php artisan make:api-resource post # With extras php artisan make:api-resource post --policy --dto --exception --tests # Custom subfolder / API version php artisan make:api-resource post --subfolder=v1/Admin php artisan make:api-resource post --api-version=v1 # Multiple resources in one run php artisan make:api-resource post comment tag --tests php artisan make:api-resource post,comment,tag # Bulk via manifest (skips interactive prompts) php artisan make:api-resource --manifest=resources.json # Preview only, writes nothing php artisan make:api-resource post --policy --dto --dry-run
resources.json example:
[
{ "name": "post", "policy": true, "dto": true, "tests": true },
{ "name": "comment", "subfolder": "v1/Admin" },
{ "name": "tag", "api_version": "v1", "exception": true }
]
Notes
--exceptiongenerates a{Model}ConflictExceptionwith its ownrender()method - Laravel calls that automatically, so no edits to your app's global exception handler are needed.--dtogenerates a generic typed wrapper ({Model}Data) around the validated array, with a TODO comment showing how to add explicit typed properties once your fields are finalized.--policywires a basiccreate/updateability check into the Form Request based on HTTP verb; refine it for ownership-style checks that need the specific model instance.
Requirements
- PHP 8.1+
- Laravel 10, 11, 12 or 13
License
MIT — see LICENSE.md.