laravel-specialist

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Laravel Specialist

Laravel 专家

Purpose

用途

Provides expert guidance on Laravel framework development using modern Laravel 11+ features, Livewire 3, and PHP 8.3. Specializes in building scalable web applications, APIs, real-time features, and performance optimization with Octane.
提供使用现代Laravel 11+特性、Livewire 3和PHP 8.3进行Laravel框架开发的专业指导。专注于构建可扩展Web应用、API、实时功能,以及借助Octane进行性能优化。

When to Use

适用场景

  • Building new Laravel applications or APIs
  • Implementing Livewire 3 reactive components
  • Optimizing Laravel performance with Octane
  • Designing Eloquent models and relationships
  • Creating custom Artisan commands
  • Implementing Laravel queues and jobs
  • Building real-time features with Broadcasting
  • Setting up Laravel Sail or deployment
  • 构建新的Laravel应用或API
  • 实现Livewire 3响应式组件
  • 借助Octane优化Laravel性能
  • 设计Eloquent模型及关联关系
  • 创建自定义Artisan命令
  • 实现Laravel队列与任务
  • 借助Broadcasting构建实时功能
  • 搭建Laravel Sail环境或部署应用

Quick Start

快速入门

Invoke this skill when:
  • Developing Laravel web applications or APIs
  • Building reactive UIs with Livewire 3
  • Optimizing performance with Octane or caching
  • Working with Eloquent ORM patterns
  • Implementing Laravel ecosystem packages
Do NOT invoke when:
  • Generic PHP without Laravel → use
    /php-pro
  • WordPress development → use
    /wordpress-master
  • Frontend JavaScript frameworks → use
    /vue-expert
    or
    /react-specialist
  • Database design independent of Laravel → use
    /database-administrator
在以下场景调用此技能:
  • 开发Laravel Web应用或API
  • 借助Livewire 3构建响应式UI
  • 借助Octane或缓存优化性能
  • 处理Eloquent ORM相关开发
  • 集成Laravel生态包
请勿在以下场景调用:
  • 无Laravel的通用PHP开发 → 使用
    /php-pro
  • WordPress开发 → 使用
    /wordpress-master
  • 前端JavaScript框架开发 → 使用
    /vue-expert
    /react-specialist
  • 独立于Laravel的数据库设计 → 使用
    /database-administrator

Decision Framework

决策框架

Feature Type?
├── Interactive UI
│   ├── Complex SPA → Inertia.js + Vue/React
│   └── Reactive components → Livewire 3
├── API
│   ├── Simple REST → Laravel API Resources
│   └── Complex → Laravel + Sanctum/Passport
├── Background Processing
│   └── Laravel Queues with Redis/SQS
└── Real-time
    └── Laravel Echo + Pusher/Soketi
Feature Type?
├── Interactive UI
│   ├── Complex SPA → Inertia.js + Vue/React
│   └── Reactive components → Livewire 3
├── API
│   ├── Simple REST → Laravel API Resources
│   └── Complex → Laravel + Sanctum/Passport
├── Background Processing
│   └── Laravel Queues with Redis/SQS
└── Real-time
    └── Laravel Echo + Pusher/Soketi

Core Workflows

核心工作流

1. Laravel 11 Application Setup

1. Laravel 11应用搭建

  1. Create project with
    laravel new --using=sail
  2. Configure environment and database
  3. Set up authentication (Breeze/Jetstream)
  4. Define models with migrations
  5. Implement routes and controllers
  6. Add middleware and policies
  1. 使用
    laravel new --using=sail
    创建项目
  2. 配置环境与数据库
  3. 搭建认证系统(Breeze/Jetstream)
  4. 定义模型及迁移
  5. 实现路由与控制器
  6. 添加中间件与策略

2. Livewire 3 Component Development

2. Livewire 3组件开发

  1. Create Livewire component class
  2. Define public properties and methods
  3. Build Blade template with wire directives
  4. Implement validation and actions
  5. Add Alpine.js for client-side enhancements
  6. Test with Livewire testing utilities
  1. 创建Livewire组件类
  2. 定义公共属性与方法
  3. 编写带有wire指令的Blade模板
  4. 实现验证逻辑与操作
  5. 集成Alpine.js增强客户端交互
  6. 使用Livewire测试工具进行测试

3. Performance Optimization

3. 性能优化

  1. Enable Octane with Swoole/RoadRunner
  2. Implement query caching and eager loading
  3. Use Redis for session and cache
  4. Optimize Composer autoloader
  5. Configure OPcache settings
  6. Set up queue workers for async tasks
  1. 启用基于Swoole/RoadRunner的Octane
  2. 实现查询缓存与预加载
  3. 使用Redis存储会话与缓存
  4. 优化Composer自动加载器
  5. 配置OPcache设置
  6. 为异步任务搭建队列 worker

Best Practices

最佳实践

  • Use strict types and PHP 8.3 features (readonly, enums)
  • Eager load relationships to avoid N+1 queries
  • Implement form requests for validation
  • Use Laravel Pint for consistent code style
  • Write feature tests with Laravel's testing utilities
  • Leverage Laravel's built-in security features
  • 使用严格类型与PHP 8.3特性(readonly、枚举)
  • 预加载关联关系以避免N+1查询问题
  • 使用表单请求类处理验证逻辑
  • 使用Laravel Pint保证代码风格一致
  • 借助Laravel测试工具编写功能测试
  • 充分利用Laravel内置安全特性

Anti-Patterns

反模式

Anti-PatternProblemCorrect Approach
Fat controllersHard to test and maintainMove logic to Actions/Services
N+1 queriesPerformance degradationEager loading with
with()
Raw SQL everywhereLoses Eloquent benefitsUse Eloquent, raw only when needed
Ignoring queuesSlow user responsesQueue slow operations
No cachingUnnecessary DB loadCache expensive queries
反模式问题正确做法
臃肿控制器难以测试与维护将逻辑迁移至Actions/Services
N+1查询性能下降使用
with()
进行预加载
大量使用原生SQL失去Eloquent的优势优先使用Eloquent,仅在必要时使用原生SQL
忽略队列用户响应缓慢将耗时操作放入队列
不使用缓存数据库负载过高对耗时查询进行缓存