Build production-grade Laravel REST APIs with clean architecture and type safety. Ideal for operations teams to streamline API development and ensure adherence to Laravel best practices. Connects to Laravel frameworks and integrates with existing development workflows.
git clone https://github.com/JustSteveKing/laravel-api-skill.gitThe Laravel API Skill for Claude guides you through building stateless, boundary-first REST APIs using Laravel's official code quality standards. It implements resource-scoped organization, namespace-based versioning, strict type safety with PSR-12 compliance, and opinionated action-based architecture patterns. The skill includes comprehensive guides on controllers, form requests, DTOs, actions, and models with templates for each component. Development teams benefit from standardized JSON responses, consistent error handling using RFC 7807 Problem+JSON format, and built-in code review checklists that enforce Laravel best practices. Installation works via Claude.ai, Claude app, or Claude Code plugin marketplace.
[{"step":"Define your API requirements","action":"Replace [PROJECT_NAME], [ENDPOINTS], [RESOURCES], and [VALIDATION_RULES] in the prompt with your specific needs. For example, if building an e-commerce API, specify endpoints like `/api/v1/products`, `/api/v1/orders`, and validation rules for product creation.","tip":"Use Laravel’s built-in scaffolding tools like `php artisan make:model Task -a` to generate a base structure, then customize it with the AI-generated code."},{"step":"Generate the API skeleton","action":"Paste the customized prompt into your AI tool (e.g., Claude, ChatGPT) and execute it. Review the generated code for Laravel best practices, such as proper namespace usage, dependency injection, and type safety.","tip":"Ensure the AI includes PestPHP tests for critical business logic. If tests are missing, ask the AI to generate them."},{"step":"Set up the Laravel environment","action":"Install Laravel dependencies with `composer install`, configure your `.env` file, and run migrations with `php artisan migrate`. Use Laravel Pint (`composer require laravel/pint --dev`) to enforce code style.","tip":"Run `./vendor/bin/pint` to auto-format the generated code and catch style issues early."},{"step":"Implement and test","action":"Manually review the generated code for edge cases (e.g., database transactions, rate limiting). Use Laravel Telescope or Laravel Debugbar to monitor API performance. Write additional PestPHP tests for edge cases like validation failures or database errors.","tip":"Use Laravel’s `php artisan tinker` to interactively test API logic before writing full tests."},{"step":"Document and deploy","action":"Generate API documentation using Laravel Swagger (`composer require zircote/swagger-php`) or OpenAPI annotations. Deploy the API using Laravel Forge, Herd, or a CI/CD pipeline like GitHub Actions.","tip":"Use `php artisan l5-swagger:generate` to auto-generate Swagger docs from your code annotations."}]
Build task management APIs with CRUD operations and resource-scoped routing
Implement JWT authentication endpoints with validation and DTO transformation
Refactor existing Laravel controllers to follow boundary-first architecture patterns
Create versioned API endpoints with HTTP Sunset headers for deprecation
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/JustSteveKing/laravel-api-skillCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Build a production-grade Laravel REST API for [PROJECT_NAME] that follows clean architecture principles and enforces strict type safety. The API should include: [ENDPOINTS], [RESOURCES], and [VALIDATION_RULES]. Use Laravel's latest features like Laravel Pint for code style, Laravel Prompts for scaffolding, and Laravel Pint for static analysis. Generate a complete API skeleton with controllers, services, repositories, and DTOs. Include proper exception handling, logging, and API resource transformations. Write unit tests using PestPHP for the core business logic. Document the API using Laravel Swagger or OpenAPI annotations.
Here’s a production-ready Laravel REST API skeleton for **TaskFlow**, a project management tool, designed for high scalability and maintainability. The API includes endpoints for managing tasks, projects, and users with full type safety and clean architecture.
### **Project Structure**
```
app/
├── Http/
│ ├── Controllers/
│ │ ├── Api/
│ │ │ ├── v1/
│ │ │ │ ├── TaskController.php
│ │ │ │ ├── ProjectController.php
│ │ │ │ └── UserController.php
│ ├── Requests/
│ │ ├── TaskRequest.php
│ │ ├── ProjectRequest.php
│ │ └── UserRequest.php
├── Models/
│ ├── Task.php
│ ├── Project.php
│ └── User.php
├── DTOs/
│ ├── TaskDTO.php
│ ├── ProjectDTO.php
│ └── UserDTO.php
├── Repositories/
│ ├── TaskRepository.php
│ ├── ProjectRepository.php
│ └── UserRepository.php
├── Services/
│ ├── TaskService.php
│ ├── ProjectService.php
│ └── UserService.php
└── Providers/
└── AppServiceProvider.php
```
### **Key Features**
1. **Type Safety**: All DTOs, requests, and responses are strictly typed using PHP 8.2+ features.
2. **Clean Architecture**: Separation of concerns with controllers, services, repositories, and DTOs.
3. **Validation**: Custom request classes for endpoint validation.
4. **Error Handling**: Global exception handling with Laravel’s `Renderable` and `Reportable` interfaces.
5. **Testing**: PestPHP unit tests for services and repositories.
6. **Documentation**: OpenAPI (Swagger) annotations for API documentation.
### **Example Endpoints**
- `GET /api/v1/tasks` – List all tasks with pagination.
- `POST /api/v1/tasks` – Create a new task with validation.
- `PUT /api/v1/tasks/{id}` – Update a task.
- `DELETE /api/v1/tasks/{id}` – Delete a task.
### **Code Snippets**
**TaskController.php**
```php
<?php
namespace App\Http\Controllers\Api\v1;
use App\DTOs\TaskDTO;
use App\Http\Requests\TaskRequest;
use App\Http\Resources\TaskResource;
use App\Services\TaskService;
use Illuminate\Http\JsonResponse;
class TaskController extends Controller
{
public function __construct(private TaskService $taskService) {}
public function index(): JsonResponse
{
$tasks = $this->taskService->getAll();
return TaskResource::collection($tasks)->response();
}
public function store(TaskRequest $request): JsonResponse
{
$taskDTO = TaskDTO::fromRequest($request);
$task = $this->taskService->create($taskDTO);
return (new TaskResource($task))->response()->setStatusCode(201);
}
}
```
**TaskDTO.php**
```php
<?php
namespace App\DTOs;
use Illuminate\Http\Request;
class TaskDTO
{
public function __construct(
public string $title,
public string $description,
public int $project_id,
public ?int $assigned_to = null,
public ?string $due_date = null,
) {}
public static function fromRequest(Request $request): self
{
return new self(
title: $request->input('title'),
description: $request->input('description'),
project_id: $request->input('project_id'),
assigned_to: $request->input('assigned_to'),
due_date: $request->input('due_date'),
);
}
}
```
### **Testing**
A PestPHP test for the `TaskService` ensures business logic is validated:
```php
it('can create a task', function () {
$taskDTO = new TaskDTO(
title: 'Test Task',
description: 'This is a test task',
project_id: 1,
);
$task = $this->taskService->create($taskDTO);
expect($task)->toBeInstanceOf(Task::class);
expect($task->title)->toBe('Test Task');
});
```
### **Next Steps**
1. Run `composer install` to install dependencies.
2. Configure `.env` with database and API settings.
3. Run `php artisan migrate` to set up tables.
4. Use `php artisan serve` to test locally.
5. Generate API docs with `php artisan l5-swagger:generate`.Real-time collaborative writing platform
AI assistant built for thoughtful, nuanced conversation
IronCalc is a spreadsheet engine and ecosystem
Customer feedback management made simple
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan