api-endpoint

Creates and modifies Laravel API endpoints with middleware placement, validation, and response conventions.

Updated May 5, 2025
One-click install
npx skills add https://github.com/sebauvray/toollab-api --skill api-endpoint-sebauvray
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: api-endpoint
Source: https://github.com/sebauvray/toollab-api/tree/main/.claude/skills/api-endpoint
Command: npx skills add https://github.com/sebauvray/toollab-api --skill api-endpoint-sebauvray

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Adding or modifying an endpoint in the Toollab Laravel API requires navigating a cascade of middleware groups (auth, school, schoolyear, checkrole), strict response formats, French validation messages, and pagination contracts. This Skill encodes all of those conventions so new endpoints are placed correctly and follow the project's established patterns instead of introducing inconsistencies or security gaps. ## Core Features & Use Cases - Middleware placement guide: Maps every route group in routes/api.php (public, auth:sanctum, school, schoolyear, checkrole) so mutative routes land under the right security context. - Controller skeleton and response contract: Enforces the {status, message, data} JSON format, DB transactions for multi-table writes, and mandatory Log::error calls in catch blocks. - Validation and authorization rules: Provides French validation messages (no lang/ files exist), school-scoped Rule::exists constraints, and reusable gates like callerCanAccessFamily and guardClassroom. - Pagination and file responses: Standardizes per_page defaults (10, capped at 100, lower-bounded) and BinaryFileResponse patterns for XLSX exports and PDF invoices. - Use Case: When asked to add a POST endpoint for creating classrooms, the Skill directs you to place it under the schoolyear group with checkrole:director,admin, validate cursus_id against the current school, wrap writes in a transaction, and return the standard 201 response. ## Quick Start Ask the AI to create a new API endpoint for a Toollab resource, for example: add a POST endpoint to create a classroom following the api-endpoint conventions.

Frequently Asked Questions about api-endpoint

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new API endpoint in a Laravel routes/api.php file?▼

Place the route inside the correct middleware group: public routes at the root with throttle, authenticated routes under auth:sanctum, school-context routes under the school middleware, and mutative routes touching pedagogical or financial data under schoolyear. Add checkrole middleware when the endpoint is role-restricted.

How do I avoid Laravel route parameter collisions with literal segments?▼

Declare literal routes like families/export before parameterized ones like families/{family}, or add a ->whereNumber('user') constraint so numeric-only parameters do not capture literal segments such as /users/teachers. Both mechanisms coexist in this project's routes/api.php.

Why do Laravel validation messages appear in English instead of French?▼

The project has APP_LOCALE=en and no lang/ directory, so default Laravel validation messages render in English. Every user-facing rule needs a manual French message via $request->validate($rules, $messages) or a messages() method in a FormRequest.

Why does Laravel pagination throw DivisionByZeroError with per_page=0?▼

Passing per_page=0 or a non-numeric value casts to 0, causing ceil($total / 0) to fail. Guard both bounds with max(1, min((int) $request->input('per_page', 10), 100)) and also cast the page parameter to avoid TypeError in PHP 8.

Should a Laravel catch block return a 500 response directly?▼

Only if it also logs the exception, because a catch that returns its own formatted 500 bypasses the global exception handler in bootstrap/app.php. Always call Log::error with the exception, caller id, and path before returning the generic error message.