laravel-11-12-app-guidelines
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLaravel 11/12 App Guidelines
Laravel 11/12 应用开发指南
Overview
概述
Apply a consistent workflow for Laravel 11/12 apps with optional frontend stacks, Dockerized commands, and Laravel Boost tooling.
为带有可选前端技术栈、Docker化命令和Laravel Boost工具的Laravel 11/12应用采用统一的工作流。
Quick Start
快速开始
- Read repository instructions first: . If
AGENTS.mdexists, readdocs/and relevant module docs before decisions.docs/README.md - Detect the stack and command locations; do not guess.
- Use Laravel Boost for Laravel ecosystem guidance; use Context7 only if Boost docs are unavailable.
search-docs - Follow repo conventions for naming, UI language, docs-first policies, and existing component patterns.
- 首先阅读仓库说明:。如果存在
AGENTS.md目录,请在做决策前阅读docs/及相关模块文档。docs/README.md - 检测技术栈和命令位置,切勿猜测。
- 使用Laravel Boost的获取Laravel生态系统指南;仅当Boost文档不可用时才使用Context7。
search-docs - 遵循仓库的命名规范、UI语言、文档优先策略以及现有组件模式。
Stack Detection
技术栈检测
- Check ,
composer.json,package.json, anddocker-compose.*to confirm:config/*- Docker Compose/Sail vs host commands
- API-only vs full-stack
- Frontend framework (Inertia/React, Livewire, Vue, Blade)
- Auth (Fortify, Sanctum, Passport, custom)
- 检查、
composer.json、package.json和docker-compose.*文件以确认:config/*- 使用Docker Compose/Sail还是本地主机命令
- 仅API还是全栈模式
- 前端框架(Inertia/React、Livewire、Vue、Blade)
- 认证方式(Fortify、Sanctum、Passport、自定义)
Laravel 11/12 Core Conventions
Laravel 11/12 核心规范
- Use the Laravel 11/12 structure: configure middleware, exceptions, and routes in ; service providers in
bootstrap/app.php; console configuration inbootstrap/providers.php.routes/console.php - Use Eloquent models and relationships first; avoid raw queries and unless truly necessary.
DB:: - Create Form Request classes for validation instead of inline validation.
- Prefer named routes and for URL generation.
route() - When altering columns, include all existing attributes in the migration to avoid dropping them.
- Ask before destructive database operations (e.g., reset/rollback/fresh).
- 采用Laravel 11/12的结构:在中配置中间件、异常和路由;在
bootstrap/app.php中配置服务提供者;在bootstrap/providers.php中配置控制台命令。routes/console.php - 优先使用Eloquent模型及关联关系;除非确有必要,否则避免使用原生查询和方法。
DB:: - 创建Form Request类进行验证,而非内联验证。
- 优先使用命名路由和方法生成URL。
route() - 修改数据库列时,迁移文件中需包含所有现有属性,避免意外删除。
- 执行破坏性数据库操作(如重置/回滚/刷新)前需确认。
API-Only Mode
仅API模式
- Use ; avoid Inertia and frontend assumptions.
routes/api.php - Prefer API Resources and versioning if the repo already uses them.
- Follow the repo's auth stack (Sanctum/Passport/custom) and response format conventions.
- Do not require Vite/Tailwind/NPM unless the repo already includes them.
- 使用;避免依赖Inertia和前端相关假设。
routes/api.php - 如果仓库已使用API资源和版本控制,请遵循该规范。
- 遵循仓库的认证技术栈(Sanctum/Passport/自定义)和响应格式规范。
- 除非仓库已包含Vite/Tailwind/NPM,否则不要强制要求使用。
Inertia + React + Wayfinder (if present)
Inertia + React + Wayfinder(若存在)
- Use for server-side routing; place pages under
Inertia::render()unless the repo says otherwise.resources/js/Pages - Use or
<Form>for Inertia forms; add skeleton/empty states for deferred props.useForm - Use or
<Link>for navigation.router.visit() - Use Wayfinder named imports for tree-shaking; avoid default imports; regenerate routes after changes if required.
- 使用进行服务端路由;页面默认放在
Inertia::render()目录下,除非仓库另有规定。resources/js/Pages - 使用或
<Form>处理Inertia表单;为延迟加载的属性添加骨架屏/空状态。useForm - 使用或
<Link>进行导航。router.visit() - 使用Wayfinder的命名导入以实现树摇优化;避免默认导入;修改后若需要则重新生成路由。
Livewire / Vue / Blade (if present)
Livewire / Vue / Blade(若存在)
- Follow existing component patterns and conventions; do not mix frameworks unless the repo already does.
- Keep UI strings in the repo's expected language.
- 遵循现有组件模式和规范;除非仓库已混合使用,否则不要混用框架。
- UI文本需符合仓库指定的语言。
Tailwind CSS v4 (if present)
Tailwind CSS v4(若存在)
- Use and
@import "tailwindcss";for tokens.@theme - Avoid deprecated utilities; use replacements (e.g., ,
shrink-*,grow-*).text-ellipsis - Use for spacing between items; follow existing dark mode conventions if present.
gap-*
- 使用和
@import "tailwindcss";定义令牌。@theme - 避免使用已废弃的工具类;使用替代方案(如、
shrink-*、grow-*)。text-ellipsis - 使用设置元素间距;若存在暗色模式规范,请遵循。
gap-*
Testing and Formatting
测试与格式化
- Use PHPUnit; generate tests with and prefer feature tests.
php artisan make:test --phpunit - Run the minimal relevant tests (or
php artisan test <file>).--filter= - Run before finalizing code changes.
vendor/bin/pint --dirty - After minimal tests pass, offer to run the full test suite.
- 使用PHPUnit;通过生成测试,优先编写功能测试。
php artisan make:test --phpunit - 运行最小范围的相关测试(或
php artisan test <file>参数)。--filter= - 最终确定代码修改前,运行。
vendor/bin/pint --dirty - 最小范围测试通过后,可主动提出运行完整测试套件。
Laravel Boost MCP Tools (when available)
Laravel Boost MCP工具(若可用)
- before changing behavior or using framework features.
search-docs - to confirm Artisan options.
list-artisan-commands - to inspect routing changes.
list-routes - for PHP debugging and
tinkerfor read-only DB checks.database-query - to inspect frontend errors.
browser-logs - for sharing project URLs.
get-absolute-url - See for query patterns and tool usage tips.
references/boost-tools.md
- 修改行为或使用框架功能前,先使用。
search-docs - 使用确认Artisan命令选项。
list-artisan-commands - 使用检查路由变更。
list-routes - 使用进行PHP调试,使用
tinker进行只读数据库检查。database-query - 使用查看前端错误。
browser-logs - 使用分享项目URL。
get-absolute-url - 查看获取查询模式和工具使用技巧。
references/boost-tools.md
Output Expectations
输出要求
- Preserve existing architecture, structure, and dependencies unless the user explicitly requests changes.
- Reuse existing components and follow local patterns.
- Ask concise clarifying questions when repo guidance is missing or ambiguous.
- 除非用户明确要求更改,否则保留现有架构、结构和依赖。
- 复用现有组件并遵循本地模式。
- 当仓库指南缺失或模糊时,提出简洁的澄清问题。