Spatie Laravel Php

spatie/guidelines-skills/resources/boost/skills/spatie-laravel-php

作者 spatiec31006972d0b8c8db71e7b75c1b1d505b479023dMIT收錄於 2026年10月9日更新於 2026年10月9日

Apply Spatie's Laravel and PHP coding standards for any task that creates, edits, reviews, refactors, or formats Laravel/PHP code or Blade templates; use for controllers, Eloquent models, routes, config, validation, migrations, tests, and related files to align with Laravel conventions and PSR-12.

AI 產生的概覽

在撰寫、編輯、審查或重構 Laravel/PHP 程式碼與 Blade 樣板時,套用 Spatie 的 Laravel 與 PHP 編碼標準。

功能
此技能引導代理遵循 Spatie 的 Laravel 與 PHP 指南,讓產生或修改的程式碼維持一致並符合 Laravel 原生風格。它涵蓋控制器、Eloquent 模型、路由、設定、驗證、遷移、測試與 Blade 樣板,先套用 Laravel 慣例,再套用 PSR-1、PSR-2 與 PSR-12。它產出的是程式碼變更與符合規範的審查意見,而非獨立檔案,並指向隨附的參考文件以取得各章節的具體規則。
適用情境
適用於任何 Laravel 或 PHP 編碼工作,即使使用者未提及 Spatie。適合產生、編輯、格式化、重構或審查 .php 與 .blade.php 檔案、路由、控制器、模型、設定、驗證、遷移與測試。不適用於 JS/TS、CSS、基礎架構、資料庫結構設計或非 Laravel 框架。
執行需求
不需要指令碼或特殊工具,僅為指示。它依賴隨附的參考檔案 references/spatie-laravel-php-guidelines.md,由代理讀取。不需要憑證或網路存取。

Spatie Laravel & PHP Guidelines

Overview

Apply Spatie's Laravel and PHP guidelines to keep code style consistent and Laravel-native.

When to Activate

  • Activate this skill for any Laravel or PHP coding work, even if the user does not explicitly mention Spatie.
  • Activate this skill when asked to generate, edit, format, refactor, review, or align Laravel/PHP code.
  • Activate this skill when working on .php or .blade.php files, routes, controllers, models, config, validation, migrations, or tests.

Scope

  • In scope: .php, .blade.php, Laravel conventions (routes, controllers, config, validation, migrations, tests).
  • Out of scope: JS/TS, CSS, infrastructure, database schema design, non-Laravel frameworks.

Workflow

  1. Identify the artifact (controller, route, config, model, Blade, test, etc.).
  2. Read references/spatie-laravel-php-guidelines.md and focus on the relevant sections.
  3. Apply the core Laravel principle first, then PHP standards, then section-specific rules.
  4. If a rule conflicts with existing project conventions, follow Laravel conventions and keep changes consistent.

Core Rules (Summary)

  • Follow Laravel conventions first.
  • Follow PSR-1, PSR-2, and PSR-12.
  • Prefer typed properties and explicit return types (including void).
  • Use short nullable syntax like ?string.
  • Use constructor property promotion when all properties can be promoted.
  • One trait per line with separate use statements.
  • Once a method chain breaks across lines, put every subsequent -> on a new line; never mix single-line and multi-line chaining.
  • Prefer early returns and avoid else when possible.
  • Always use curly braces for control structures.
  • Use string interpolation over concatenation.
  • Happy path last: handle error conditions first.

Do and Don't

Do:

  • Use kebab-case URLs, camelCase route names, and camelCase route parameters.
  • Use tuple notation for routes: [Controller::class, 'method'].
  • Use plural resource names for controllers (PostsController).
  • Use array notation for validation rules.
  • Use config() helper and avoid env() outside config files.
  • Add service configs to config/services.php, not new files.
  • Use __() for translations instead of @lang.
  • Use PascalCase for enum values and class constants.

Don't:

  • Add docblocks when full type hints already exist.
  • Use fully qualified classnames in docblocks.
  • Use final or readonly by default.
  • Use else when early returns work.
  • Add spaces after Blade control structures.

Examples

php
// Happy path last with early returnsif (! $user) {    return null;}
if (! $user->isActive()) {    return null;}
// Process active user...
// Short ternary$name = $isFoo ? 'foo' : 'bar';
// Constructor property promotionclass MyClass {    public function __construct(        protected string $firstArgument,        protected string $secondArgument,    ) {}}
blade
@if($condition)    Something@endif

References

  • references/spatie-laravel-php-guidelines.md

來源與署名

來源:spatie/guidelines-skills位於resources/boost/skills/spatie-laravel-php提交c310069

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架