Communitygithub.com

Laravel 驗證循環

針對 Laravel 專案的驗證循環:環境檢查、程式碼格式化、靜態分析、測試與覆蓋率、安全掃描及部署就緒檢查。在合併或部署前驗證 Laravel 專案時使用——包含格式化、靜態分析、測試、覆蓋率及安全性。

Laravel 驗證循環 是什麼?

這個 Laravel 驗證循環技能提供了一個結構化的七階段流程,用於在合併或部署前驗證 Laravel 專案。它涵蓋環境檢查、Composer 驗證、程式碼格式化 (Pint)、靜態分析 (PHPStan/Psalm)、測試與覆蓋率 (PHPUnit)、安全性稽核、資料庫遷移審查、快取優化以及佇列/排程器檢查。該技能可與 Claude Code 或其他 AI 代理工具搭配使用,以確保 Laravel 應用程式的品質與部署就緒性。它支援本機開發環境 (包括 Laravel Sail) 以及 CI/CD 流程。每個階段都以上一個階段為基礎,形成完整的驗證管道:若環境檢查失敗則立即停止,後續階段則在測試執行後才進行安全與遷移審查。這有助於開發人員在合併或部署前,一致地捕捉常見錯誤、安全漏洞與設定問題。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/laravel-verification

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Laravel 驗證循環 是做什麼的?

請在 Pull Request 之前、重大變更之後以及部署前執行。

使用時機

  • 在為 Laravel 專案發起 Pull Request 之前
  • 在進行重大重構或依賴升級之後
  • 在準備部署至 staging 或 production 環境之前
  • 執行完整的格式化 -> 測試 -> 安全 -> 部署就緒管道

運作方式

  • 按照環境檢查到部署就緒的順序,依序執行各階段,使每一層都建立在前一層的基礎上。
  • 環境與 Composer 檢查是所有後續步驟的閘門;若它們失敗,則立即停止。
  • 在執行完整測試與覆蓋率之前,應先完成格式化/靜態分析。
  • 安全與遷移審查在測試之後進行,以便在進行資料或發佈步驟前先驗證行為。
  • 建置/部署就緒與佇列/排程器檢查是最終閘門;任何失敗都會封鎖發佈。

階段 1:環境檢查

php -v
composer --version
php artisan --version
  • 確認 .env 檔案存在且必要的金鑰已設定
  • 確認生產環境中 APP_DEBUG=false
  • 確認 APP_ENV 與目標部署環境相符(production、staging)

若在本機使用 Laravel Sail:

./vendor/bin/sail php -v
./vendor/bin/sail artisan --version

階段 1.5:Composer 與自動載入

composer validate
composer dump-autoload -o

階段 2:格式化與靜態分析

vendor/bin/pint --test
vendor/bin/phpstan analyse

若您的專案使用 Psalm 而非 PHPStan:

vendor/bin/psalm

階段 3:測試與覆蓋率

php artisan test

覆蓋率(CI 環境):

XDEBUG_MODE=coverage php artisan test --coverage

CI 範例(格式化 -> 靜態分析 -> 測試):

vendor/bin/pint --test
vendor/bin/phpstan analyse
XDEBUG_MODE=coverage php artisan test --coverage

階段 4:安全性與依賴檢查

composer audit

階段 5:資料庫與遷移

php artisan migrate --pretend
php artisan migrate:status
  • 仔細審查可能造成破壞的遷移
  • 確保遷移檔案名稱遵循 Y_m_d_His_* 格式(例如 2025_03_14_154210_create_orders_table.php),並清楚描述變更內容
  • 確保可以進行回滾
  • 驗證 down() 方法,並避免在沒有明確備份的情況下造成不可逆的資料損失

階段 6:建置與部署就緒

php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
  • 確保在生產環境設定中快取熱身成功
  • 驗證佇列工作者與排程器已正確設定
  • 確認目標環境中 storage/ 與 bootstrap/cache/ 目錄可寫入

階段 7:佇列與排程器檢查

php artisan schedule:list
php artisan queue:failed

若使用 Horizon:

php artisan horizon:status

若 queue:monitor 指令可用,請使用它來檢查積壓情況,而不實際處理任務:

php artisan queue:monitor default --max=100

主動驗證(僅限 staging 環境):將一個空操作任務分派到專用佇列,並執行單一工作者來處理它(確保已設定非 sync 佇列連線)。

php artisan tinker --execute="dispatch((new App\\Jobs\\QueueHealthcheck())->onQueue('healthcheck'))"
php artisan queue:work --once --queue=healthcheck

驗證任務產生了預期的副作用(日誌條目、健康檢查表格記錄或指標)。

僅在非生產環境且安全處理測試任務時執行此操作。

範例

最小流程:

php -v
composer --version
php artisan --version
composer validate
vendor/bin/pint --test
vendor/bin/phpstan analyse
php artisan test
composer audit
php artisan migrate --pretend
php artisan config:cache
php artisan queue:failed

CI 風格管道:

composer validate
composer dump-autoload -o
vendor/bin/pint --test
vendor/bin/phpstan analyse
XDEBUG_MODE=coverage php artisan test --coverage
composer audit
php artisan migrate --pretend
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan schedule:list

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相關技能