Laravel API
Reads routes/api.php and files in database/migrations/ to generate REST tools for a Laravel API project.
Prerequisites
Section titled “Prerequisites”- A Laravel 10 or 11 project folder.
- To run the demo server: PHP 8.2 or newer and Composer.
appctlinstalled.
The demo in this repo
Section titled “The demo in this repo”examples/demos/laravel-api/ is a minimal Laravel 11 app with Post and Comment resources registered through Route::apiResource. The routes file and migrations are committed, so the sync runs without PHP installed.
Sync without running PHP
Section titled “Sync without running PHP”cd examples/demos/laravel-apiappctl sync --laravel . --base-url http://127.0.0.1:8002 --forceReal output:
Synced Laravel: 2 resources, 10 tools written to .appctlGenerated tools:
post: posts_list GET /api/posts, post_get GET /api/posts/{id}, post_create POST /api/posts, post_update PATCH /api/posts/{id}, post_delete DELETE /api/posts/{id}comment: same five tools under /api/commentsRun the live server (optional)
Section titled “Run the live server (optional)”PHP 8.2 or newer and Composer are required. Install Composer from getcomposer.org if your system does not have it.
php -v # 8.2 or highercomposer -V # should exist
cd examples/demos/laravel-apicomposer installcp .env.example .env # if present, or create .envphp artisan key:generatetouch database/database.sqlitephp artisan migratephp artisan serve --host=127.0.0.1 --port=8002Check:
curl -s -X POST http://127.0.0.1:8002/api/posts \ -H "Content-Type: application/json" \ -d '{"title":"hi","body":"hello"}'The static sync is independent of the live server, so the tool list above is correct even if Composer is not installed on your box.
What appctl reads
Section titled “What appctl reads”routes/api.php: onlyRoute::apiResource('foos', FooController::class)lines are parsed. Manually defined routes are ignored.database/migrations/*.php:Schema::createblocks for column names and types.
Known limits
Section titled “Known limits”- Middleware on routes (
->middleware('auth:sanctum')) is not represented in the generated tools. - Form Requests and custom validation rules are not extracted. Tool parameter schemas come from migration columns only.
- If you already publish a Swagger document with
l5-swagger, use--openapi.