一键导入
routing
Route file conventions for organising API and web routes. Covers file separation, naming, grouping, middleware, and route model binding.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Route file conventions for organising API and web routes. Covers file separation, naming, grouping, middleware, and route model binding.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Readonly data containers with typed factory methods (`fromArray`, `fromModel`, `fromCollection`, `fromRequest`) used to pass structured data between application layers — especially for external API responses, Eloquent models, and service boundaries. Use this skill whenever creating, reviewing, or refactoring DTOs, Data Transfer Objects, value objects for inter-layer communication, or mapping payloads from APIs, models, or collections into typed PHP objects. Also trigger when the user mentions spatie/laravel-data alternatives, data mapping, or payload normalization in a Laravel context.
Eloquent model conventions for mass assignment, casts, relationship naming, activity logging, and mandatory model tests (CRUD + relations).
Single-purpose business logic classes that encapsulate one well-defined business operation. Actions are the primary location for business logic in Laravel applications, invoked from controllers, commands, or jobs.
Albatros accounting API integration via Saloon. Use when working with app/Services/Albatros/, AlbatrosConnector, or Albatros DTOs.
Laravel Blade template conventions covering components, output escaping, security, structure, and formatting.
Artisan console command classes that serve as the CLI entry point for operations. Commands validate input and delegate all business logic to Actions or Services.
| name | routing |
| description | Route file conventions for organising API and web routes. Covers file separation, naming, grouping, middleware, and route model binding. |
| compatible_agents | ["architect","implement","refactor","review"] |
routes/web.php and routes/api.php are present and loaded.getRouteKeyName() when needed).web.php vs api.php).web routes prioritize session/CSRF/auth flow; api routes prioritize auth/throttle/binding consistency./api/v1/...) and keep version groups isolated.// routes/api.php
Route::middleware('auth:sanctum')->group(function () {
Route::apiResource('invoices', InvoiceController::class);
Route::prefix('invoices')->group(function () {
Route::post('{invoice}/pay', PayInvoiceController::class)->name('invoices.pay');
});
});
Route::middleware(['throttle:webhook'])->group(function () {
Route::post('webhooks/stripe', ProcessStripeWebhookController::class)
// Middleware ordering matters: signature check before heavy work.
->middleware([VerifyStripeSignature::class])
->name('webhooks.stripe');
});
// Implicit route model binding
Route::get('invoices/{invoice}', ShowInvoiceController::class);
// Controller resolves the model automatically
public function __invoke(Invoice $invoice): JsonResponse { ... }
// Explicit binding for custom resolution/gotchas
// App\Providers\RouteServiceProvider::boot()
Route::bind('invoice', function (string $value) {
return Invoice::where('uuid', $value)->firstOrFail();
});
// Route uses the same placeholder name: {invoice}
Route::get('invoices/{invoice}', ShowInvoiceController::class);
// Naming with resourceful convention
Route::apiResource('invoice-lines', InvoiceLineController::class);
// Generates: invoice-lines.index, invoice-lines.store, invoice-lines.show, etc.
{invoice} binds to Invoice $invoice; {invoiceId} does not.getRouteKeyName() or explicit Route::bind.withTrashed() patterns) when expected.// Soft-deleted model binding when restore/history endpoints must resolve trashed records
// routes/api.php
Route::get('invoices/{invoice}/audit', ShowInvoiceAuditController::class);
// App\Providers\RouteServiceProvider::boot()
Route::bind('invoice', function (string $value) {
return Invoice::withTrashed()->where('uuid', $value)->firstOrFail();
});
web, keep session/cookies/CSRF stack intact before auth-gated routes.api, apply auth and throttle consistently at version/group boundaries to avoid route drift.route:cache; use controller classes for cache-safe production routing.php artisan route:cache in CI and deployment pipelines after route/provider changes.route:cache as part of normal local development loop; prefer uncached routes locally for faster iteration/debugging.php artisan route:clear.php artisan route:list to verify names, middleware, and URI shape.404 when model missing).// Middleware ordering test: reject unauthenticated request before controller side effects
public function test_pay_invoice_requires_auth_before_controller_runs(): void
{
Event::fake([InvoicePaid::class]);
$this->postJson('/api/invoices/uuid-123/pay')
->assertUnauthorized();
Event::assertNotDispatched(InvoicePaid::class);
}
// Explicit 404 binding-failure test
public function test_show_invoice_returns_404_for_missing_binding(): void
{
$this->getJson('/api/invoices/non-existing-uuid')
->assertNotFound();
}
Controllers/SKILL.md — controllers that handle routesMiddleware/SKILL.md — middleware applied at the route group level