laravel-specialist
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLaravel 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 or
/vue-expert/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/SoketiFeature 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/SoketiCore Workflows
核心工作流
1. Laravel 11 Application Setup
1. Laravel 11应用搭建
- Create project with
laravel new --using=sail - Configure environment and database
- Set up authentication (Breeze/Jetstream)
- Define models with migrations
- Implement routes and controllers
- Add middleware and policies
- 使用创建项目
laravel new --using=sail - 配置环境与数据库
- 搭建认证系统(Breeze/Jetstream)
- 定义模型及迁移
- 实现路由与控制器
- 添加中间件与策略
2. Livewire 3 Component Development
2. Livewire 3组件开发
- Create Livewire component class
- Define public properties and methods
- Build Blade template with wire directives
- Implement validation and actions
- Add Alpine.js for client-side enhancements
- Test with Livewire testing utilities
- 创建Livewire组件类
- 定义公共属性与方法
- 编写带有wire指令的Blade模板
- 实现验证逻辑与操作
- 集成Alpine.js增强客户端交互
- 使用Livewire测试工具进行测试
3. Performance Optimization
3. 性能优化
- Enable Octane with Swoole/RoadRunner
- Implement query caching and eager loading
- Use Redis for session and cache
- Optimize Composer autoloader
- Configure OPcache settings
- Set up queue workers for async tasks
- 启用基于Swoole/RoadRunner的Octane
- 实现查询缓存与预加载
- 使用Redis存储会话与缓存
- 优化Composer自动加载器
- 配置OPcache设置
- 为异步任务搭建队列 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-Pattern | Problem | Correct Approach |
|---|---|---|
| Fat controllers | Hard to test and maintain | Move logic to Actions/Services |
| N+1 queries | Performance degradation | Eager loading with |
| Raw SQL everywhere | Loses Eloquent benefits | Use Eloquent, raw only when needed |
| Ignoring queues | Slow user responses | Queue slow operations |
| No caching | Unnecessary DB load | Cache expensive queries |
| 反模式 | 问题 | 正确做法 |
|---|---|---|
| 臃肿控制器 | 难以测试与维护 | 将逻辑迁移至Actions/Services |
| N+1查询 | 性能下降 | 使用 |
| 大量使用原生SQL | 失去Eloquent的优势 | 优先使用Eloquent,仅在必要时使用原生SQL |
| 忽略队列 | 用户响应缓慢 | 将耗时操作放入队列 |
| 不使用缓存 | 数据库负载过高 | 对耗时查询进行缓存 |