Agent skill

Laravel Patterns

by affaan-m in affaan-m/ECC

Laravel架构模式、路由/控制器、Eloquent ORM、服务层、队列、事件、缓存以及用于生产应用的API资源. An agent skill from affaan-m/ECC.

MITAuto-check: notesBackend & APIs

Install Laravel Patterns

skills CLI
$ npx skills add affaan-m/ECC --skill laravel-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install affaan-m/ECC laravel-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/affaan-m/ECC.git skills-src && mkdir -p .claude/skills && cp -r skills-src/docs/zh-CN/skills/laravel-patterns .claude/skills/laravel-patterns && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
laravel-patterns
GitHub stars
277k
Used in
1 other repo
Token cost
~2.1k tokens
SKILL.md length
107 words
Files
1
Skills in repo
683
Repo updated
First seen
Licence
MIT

At a glance

Laravel架构模式、路由/控制器、Eloquent ORM、服务层、队列、事件、缓存以及用于生产应用的API资源. An agent skill from affaan-m/ECC.

  • Tasks that involve Backend development
  • SKILL.md covers 适用场景, 工作原理 and 示例
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Tasks that involve ORMs and data access

What it does

Laravel Patterns is an agent skill from affaan-m/ECC. Laravel架构模式、路由/控制器、Eloquent ORM、服务层、队列、事件、缓存以及用于生产应用的API资源。

Its SKILL.md is about 2.1k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Backend & APIs, covering Backend development and ORMs and data access. It works with Laravel. The repository describes itself as: The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond. The licence is MIT.

When your agent uses it

  • Tasks that involve Backend development
  • Tasks that involve ORMs and data access

Example prompts

  • “/laravel-patterns”

What it can do on your machine

Read from SKILL.md and the folder at commit 2d515e4. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are php).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Laravel Patterns loads about 2.1k tokens when it runs. Until then it costs about 19 tokens; SKILL.md has 107 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~19
When it runs · the whole SKILL.md, loaded when a task matches
~2.1k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NoteMentions a .env fileSKILL.md:414
    * 将机密信息保存在 `.env` 中,将配置保存在 `config/*.php` 中

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from affaan-m/ECC at commit 2d515e4, republished under its MIT licence (© affaan-m). 107 words, ~2,081 tokens.

Download SKILL.mdSave it as .claude/skills/laravel-patterns/SKILL.md (or your agent's skills folder).
name
laravel-patterns
description
Laravel架构模式、路由/控制器、Eloquent ORM、服务层、队列、事件、缓存以及用于生产应用的API资源。
origin
ECC

Laravel 开发模式

适用于可扩展、可维护应用的生产级 Laravel 架构模式。

适用场景

  • 构建 Laravel Web 应用或 API
  • 构建控制器、服务和领域逻辑
  • 使用 Eloquent 模型和关系
  • 使用资源和分页设计 API
  • 添加队列、事件、缓存和后台任务

工作原理

  • 围绕清晰的边界(控制器 -> 服务/操作 -> 模型)构建应用。
  • 使用显式绑定和作用域绑定来保持路由可预测;同时仍强制执行授权以实现访问控制。
  • 倾向于使用类型化模型、转换器和作用域来保持领域逻辑一致。
  • 将 IO 密集型工作放在队列中,并缓存昂贵的读取操作。
  • 将配置集中在 config/* 中,并保持环境配置显式化。

示例

项目结构

使用具有清晰层级边界(HTTP、服务/操作、模型)的常规 Laravel 布局。

推荐布局
app/
├── Actions/            # 单一用途的用例
├── Console/
├── Events/
├── Exceptions/
├── Http/
│   ├── Controllers/
│   ├── Middleware/
│   ├── Requests/       # 表单请求验证
│   └── Resources/      # API 资源
├── Jobs/
├── Models/
├── Policies/
├── Providers/
├── Services/           # 协调领域服务
└── Support/
config/
database/
├── factories/
├── migrations/
└── seeders/
resources/
├── views/
└── lang/
routes/
├── api.php
├── web.php
└── console.php
控制器 -> 服务 -> 操作

保持控制器精简。将编排逻辑放在服务中,将单一职责逻辑放在操作中。

php
final class CreateOrderAction
{
    public function __construct(private OrderRepository $orders) {}

    public function handle(CreateOrderData $data): Order
    {
        return $this->orders->create($data);
    }
}

final class OrdersController extends Controller
{
    public function __construct(private CreateOrderAction $createOrder) {}

    public function store(StoreOrderRequest $request): JsonResponse
    {
        $order = $this->createOrder->handle($request->toDto());

        return response()->json([
            'success' => true,
            'data' => OrderResource::make($order),
            'error' => null,
            'meta' => null,
        ], 201);
    }
}
路由与控制器

为了清晰起见,优先使用路由模型绑定和资源控制器。

php
use Illuminate\Support\Facades\Route;

Route::middleware('auth:sanctum')->group(function () {
    Route::apiResource('projects', ProjectController::class);
});
路由模型绑定(作用域)

使用作用域绑定来防止跨租户访问。

php
Route::scopeBindings()->group(function () {
    Route::get('/accounts/{account}/projects/{project}', [ProjectController::class, 'show']);
});
嵌套路由和绑定名称
  • 保持前缀和路径一致,避免双重嵌套(例如 conversation 与 conversations)。
  • 使用与绑定模型匹配的单一参数名(例如,{conversation} 对应 Conversation)。
  • 嵌套时优先使用作用域绑定以强制执行父子关系。
php
use App\Http\Controllers\Api\ConversationController;
use App\Http\Controllers\Api\MessageController;
use Illuminate\Support\Facades\Route;

Route::middleware('auth:sanctum')->prefix('conversations')->group(function () {
    Route::post('/', [ConversationController::class, 'store'])->name('conversations.store');

    Route::scopeBindings()->group(function () {
        Route::get('/{conversation}', [ConversationController::class, 'show'])
            ->name('conversations.show');

        Route::post('/{conversation}/messages', [MessageController::class, 'store'])
            ->name('conversation-messages.store');

        Route::get('/{conversation}/messages/{message}', [MessageController::class, 'show'])
            ->name('conversation-messages.show');
    });
});

如果希望参数解析为不同的模型类,请定义显式绑定。对于自定义绑定逻辑,请使用 Route::bind() 或在模型上实现 resolveRouteBinding()。

php
use App\Models\AiConversation;
use Illuminate\Support\Facades\Route;

Route::model('conversation', AiConversation::class);
服务容器绑定

在服务提供者中将接口绑定到实现,以实现清晰的依赖关系连接。

php
use App\Repositories\EloquentOrderRepository;
use App\Repositories\OrderRepository;
use Illuminate\Support\ServiceProvider;

final class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->bind(OrderRepository::class, EloquentOrderRepository::class);
    }
}
Eloquent 模型模式
模型配置
php
final class Project extends Model
{
    use HasFactory;

    protected $fillable = ['name', 'owner_id', 'status'];

    protected $casts = [
        'status' => ProjectStatus::class,
        'archived_at' => 'datetime',
    ];

    public function owner(): BelongsTo
    {
        return $this->belongsTo(User::class, 'owner_id');
    }

    public function scopeActive(Builder $query): Builder
    {
        return $query->whereNull('archived_at');
    }
}
自定义转换器与值对象

使用枚举或值对象进行严格类型化。

php
use Illuminate\Database\Eloquent\Casts\Attribute;

protected $casts = [
    'status' => ProjectStatus::class,
];
php
protected function budgetCents(): Attribute
{
    return Attribute::make(
        get: fn (int $value) => Money::fromCents($value),
        set: fn (Money $money) => $money->toCents(),
    );
}
预加载以避免 N+1 问题
php
$orders = Order::query()
    ->with(['customer', 'items.product'])
    ->latest()
    ->paginate(25);
用于复杂筛选的查询对象
php
final class ProjectQuery
{
    public function __construct(private Builder $query) {}

    public function ownedBy(int $userId): self
    {
        $query = clone $this->query;

        return new self($query->where('owner_id', $userId));
    }

    public function active(): self
    {
        $query = clone $this->query;

        return new self($query->whereNull('archived_at'));
    }

    public function builder(): Builder
    {
        return $this->query;
    }
}
全局作用域与软删除

使用全局作用域进行默认筛选,并使用 SoftDeletes 处理可恢复的记录。 对于同一筛选器,请使用全局作用域或命名作用域中的一种,除非你打算实现分层行为。

php
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Builder;

final class Project extends Model
{
    use SoftDeletes;

    protected static function booted(): void
    {
        static::addGlobalScope('active', function (Builder $builder): void {
            $builder->whereNull('archived_at');
        });
    }
}
用于可重用筛选器的查询作用域
php
use Illuminate\Database\Eloquent\Builder;

final class Project extends Model
{
    public function scopeOwnedBy(Builder $query, int $userId): Builder
    {
        return $query->where('owner_id', $userId);
    }
}

// In service, repository etc.
$projects = Project::ownedBy($user->id)->get();
用于多步更新的数据库事务
php
use Illuminate\Support\Facades\DB;

DB::transaction(function (): void {
    $order->update(['status' => 'paid']);
    $order->items()->update(['paid_at' => now()]);
});
数据库迁移
命名约定
  • 文件名使用时间戳:YYYY_MM_DD_HHMMSS_create_users_table.php
  • 迁移使用匿名类(无命名类);文件名传达意图
  • 表名默认为 snake_case 且为复数形式
迁移示例
php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('orders', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('customer_id')->constrained()->cascadeOnDelete();
            $table->string('status', 32)->index();
            $table->unsignedInteger('total_cents');
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('orders');
    }
};
表单请求与验证

将验证逻辑放在表单请求中,并将输入转换为 DTO。

php
use App\Models\Order;

final class StoreOrderRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', Order::class) ?? false;
    }

    public function rules(): array
    {
        return [
            'customer_id' => ['required', 'integer', 'exists:customers,id'],
            'items' => ['required', 'array', 'min:1'],
            'items.*.sku' => ['required', 'string'],
            'items.*.quantity' => ['required', 'integer', 'min:1'],
        ];
    }

    public function toDto(): CreateOrderData
    {
        return new CreateOrderData(
            customerId: (int) $this->validated('customer_id'),
            items: $this->validated('items'),
        );
    }
}
API 资源

使用资源和分页保持 API 响应一致。

php
$projects = Project::query()->active()->paginate(25);

return response()->json([
    'success' => true,
    'data' => ProjectResource::collection($projects->items()),
    'error' => null,
    'meta' => [
        'page' => $projects->currentPage(),
        'per_page' => $projects->perPage(),
        'total' => $projects->total(),
    ],
]);
事件、任务和队列
  • 为副作用(邮件、分析)触发领域事件
  • 使用队列任务处理耗时工作(报告、导出、Webhook)
  • 优先使用具有重试和退避机制的幂等处理器
缓存
  • 缓存读密集型端点和昂贵查询
  • 在模型事件(创建/更新/删除)时使缓存失效
  • 缓存相关数据时使用标签以便于失效
配置与环境
  • 将机密信息保存在 .env 中,将配置保存在 config/*.php 中
  • 使用按环境配置覆盖,并在生产环境中使用 config:cache

© affaan-m, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in docs/zh-CN/skills/laravel-patterns of affaan-m/ECC.

Open the folder on GitHubat commit 2d515e4

Used in 1 other repository

We found 1 copy of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in affaan-m/ECC, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Laravel Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Laravel Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Laravel Patterns this skillaffaan-m/ECC277k1 repos~2.1kAutomated safety check: NotesMIT
Laravel SpecialistJeffallan/claude-skills12k1 repos~2.1kAutomated safety check: PassMIT
Laravel Query Builderhexlet-volunteers/hexlet-sicp114—~2.4kAutomated safety check: PassMIT
Php Framework Auditwgpsec/AboutSecurity1.8k—~767Automated safety check: NotesNone
Migratesoftspark/ai-toolkit179—~1.3kAutomated safety check: NotesApache-2.0
Configuring Horizoncoollabsio/coolify63k4 repos~898Automated safety check: PassMIT

Similar skills

  • Laravel Specialist

    Jeffallan/claude-skills

    Builds Laravel 10+ applications with Eloquent models, Sanctum authentication, Horizon queues, API resources and Livewire components, tested with Pest or PHPUnit.

    12k GitHub starsUsed in 1 repo~2.1k tokens
    Backend & APIsAuto-check passed
  • Laravel Query Builder

    hexlet-volunteers/hexlet-sicp

    Build filtered, sorted, and included API endpoints using spatie/laravel-query-builder.

    114 GitHub stars~2.4k tokensUpdated 6 days ago
    Backend & APIsAuto-check passed
  • Php Framework Audit

    wgpsec/AboutSecurity

    PHP 框架特定安全审计。当在 PHP 白盒审计中已识别目标使用特定框架、 需要检查框架特有安全机制和常见配置缺陷时触发。

    1.8k GitHub stars~767 tokensUpdated yesterday
    Backend & APIsAuto-check: notes
  • Migrate

    softspark/ai-toolkit

    Run/create DB migrations (Alembic, Prisma, Laravel, Django, Flyway, Drizzle); checks backup.

    179 GitHub stars~1.3k tokensUpdated 3 days ago
    DatabasesAuto-check: notes
  • Configuring Horizon

    coollabsio/coolify

    A skill your agent uses whenever the user mentions Horizon by name in a Laravel context.

    63k GitHub starsUsed in 4 repos~898 tokens
    Backend & APIsAuto-check passed
  • Geoflow

    yaojingang/GEOFlow

    Operate/develop GEOFlow CLI/Laravel/admin/API, topics/专题 and topic tasks, theme libraries/replication, sites/leads/Agent, channel sync and legacy yao-geoflow-cli/design/template migration.

    3.8k GitHub stars~722 tokensUpdated today
    Backend & APIsAuto-check passed

More from affaan-m/ECC

All 682 skills in this repo
  • Skill Stocktake

    affaan-m/ECC

    Audits your installed Claude skills and commands for quality, with a quick mode for recently changed skills and a full mode that evaluates all of them through subagents.

    277k GitHub starsUsed in 5 repos~3.1k tokens
    Auto-check passed
  • Ingests, indexes, searches, edits and monitors video, audio and live streams through the VideoDB Python SDK, returning stream links, clips and timestamps.

    277k GitHub starsUsed in 3 repos~3.5k tokens
    Auto-check: notes
  • Docs Governance

    affaan-m/ECC

    Route broad documentation-governance requests to existing ECC skills and run an opt-in, read-only audit of mapped documentation roles, links, ADR indexes, and evidence references.

    277k GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Rules Distillation

    affaan-m/ECC

    Scans installed skills for principles that recur across them and proposes rule-file changes: append, revise, add a section, create a file or leave as covered.

    277k GitHub starsUsed in 2 repos~2.3k tokens
    Auto-check passed
  • Builds DRAFT counterparty agreements from one markdown template and a small JSON spec per party, with clauses picked by the party's role.

    277k GitHub stars~2.9k tokensUpdated today
    Auto-check passed
  • Set an ECC-specific frontend design direction for production UI work.

    277k GitHub starsUsed in 1 repo~2.2k tokens
    Auto-check passed

Works with

Questions about Laravel Patterns

What does Laravel Patterns do?

Laravel架构模式、路由/控制器、Eloquent ORM、服务层、队列、事件、缓存以及用于生产应用的API资源. An agent skill from affaan-m/ECC. Laravel Patterns is an agent skill from affaan-m/ECC.

When should I use Laravel Patterns?

Laravel Patterns fits situations like: tasks that involve Backend development; tasks that involve ORMs and data access.

How do I install Laravel Patterns in Claude Code?

Run `npx skills add affaan-m/ECC --skill laravel-patterns -a claude-code`. Or copy the skill folder (docs/zh-CN/skills/laravel-patterns in affaan-m/ECC) into .claude/skills/laravel-patterns in your project. Claude Code loads it when a task matches its description.

How do I install Laravel Patterns in Codex?

Run `npx skills add affaan-m/ECC --skill laravel-patterns -a codex`. Or copy the skill folder (docs/zh-CN/skills/laravel-patterns in affaan-m/ECC) into .agents/skills/laravel-patterns in your project. Codex loads it when a task matches its description.

Can I use Laravel Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add affaan-m/ECC --skill laravel-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/laravel-patterns, .gemini/skills/laravel-patterns, .github/skills/laravel-patterns and .opencode/skills/laravel-patterns in your project.

What does Laravel Patterns need to run?

SKILL.md names no scripts, command-line tools or credentials: Laravel Patterns is instructions for the agent only.

Does Laravel Patterns access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Laravel Patterns safe to install?

Our automated static check of SKILL.md found notes only (mentions a .env file), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Laravel Patterns use?

Laravel Patterns is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Laravel Patterns use?

About 2.1k tokens (SKILL.md is roughly 8.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Laravel Patterns?

Skills that share tags, products or a category with Laravel Patterns: Laravel Specialist (Jeffallan/claude-skills, 12k stars), Laravel Query Builder (hexlet-volunteers/hexlet-sicp, 114 stars), Php Framework Audit (wgpsec/AboutSecurity, 1.8k stars) and Migrate (softspark/ai-toolkit, 179 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Laravel Patterns?

affaan-m (a GitHub user) maintains it in affaan-m/ECC, which has 276,673 GitHub stars. The repository holds 683 skills in this directory. The repository was last updated on October 11, 2026.

Source: affaan-m/ECC on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.