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 从公开仓库中收录这些内容。

举报或申请下架