laravel
Laravel PHP framework conventions and best practices. Use when building Laravel applications, writing controllers, models, migrations, routes, middleware, form requests, policies, jobs, events, or any Laravel-specific code. Triggers include "Laravel", "Eloquent", "Artisan", "php artisan", routing, migrations, or working with Laravel projects.
What this skill does
# Laravel 12
Opinionated PHP framework with expressive syntax and well-defined conventions.
## Project Structure
```
app/
├── Http/
│ ├── Controllers/ # Request handlers
│ ├── Middleware/ # HTTP middleware
│ └── Requests/ # Form request validation
├── Models/ # Eloquent models
├── Policies/ # Authorization policies
├── Jobs/ # Queueable jobs
├── Events/ # Event classes
├── Listeners/ # Event listeners
├── Mail/ # Mailable classes
└── Providers/ # Service providers
config/ # Configuration files
database/
├── migrations/ # Database migrations
├── factories/ # Model factories
└── seeders/ # Database seeders
resources/
├── views/ # Blade templates
└── css/js # Frontend assets
routes/
├── web.php # Web routes
├── api.php # API routes
└── console.php # Artisan commands
```
## Artisan Commands
```bash
# Models
php artisan make:model Post -mfsc # Model + migration, factory, seeder, controller
php artisan make:model Post --all # All resources
# Controllers
php artisan make:controller PostController --resource # CRUD controller
php artisan make:controller PostController --api # API controller
php artisan make:controller ShowPost --invokable # Single action
# Other
php artisan make:migration create_posts_table
php artisan make:request StorePostRequest
php artisan make:policy PostPolicy --model=Post
php artisan make:job ProcessPodcast
php artisan make:event OrderShipped
php artisan make:listener SendShipmentNotification
```
## Controllers
### Resource Controller
```php
class PostController extends Controller
{
public function index(): View
{
return view('posts.index', ['posts' => Post::latest()->paginate()]);
}
public function store(StorePostRequest $request): RedirectResponse
{
Post::create($request->validated());
return redirect()->route('posts.index');
}
public function show(Post $post): View // Route model binding
{
return view('posts.show', compact('post'));
}
public function update(UpdatePostRequest $request, Post $post): RedirectResponse
{
$post->update($request->validated());
return redirect()->route('posts.show', $post);
}
public function destroy(Post $post): RedirectResponse
{
$post->delete();
return redirect()->route('posts.index');
}
}
```
### Single Action Controller
```php
class ShowDashboard extends Controller
{
public function __invoke(): View
{
return view('dashboard');
}
}
```
## Routing
```php
// Resource routes
Route::resource('posts', PostController::class);
Route::apiResource('posts', PostController::class); // API (no create/edit)
// Single routes
Route::get('/dashboard', ShowDashboard::class)->name('dashboard');
Route::get('/users/{user}', [UserController::class, 'show'])->name('users.show');
// Route groups
Route::middleware(['auth'])->group(function () {
Route::get('/profile', [ProfileController::class, 'edit']);
});
// Livewire pages
Route::livewire('/posts', 'pages::posts.index');
```
## Eloquent Models
```php
class Post extends Model
{
protected $fillable = ['title', 'content', 'user_id'];
protected $casts = [
'published_at' => 'datetime',
'is_featured' => 'boolean',
];
// Relationships
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function comments(): HasMany
{
return $this->hasMany(Comment::class);
}
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class);
}
// Scopes
public function scopePublished(Builder $query): Builder
{
return $query->whereNotNull('published_at');
}
}
```
### Query Patterns
```php
// Eager loading (prevent N+1)
$posts = Post::with(['user', 'comments'])->get();
// Chunking large datasets
Post::chunk(100, function ($posts) {
foreach ($posts as $post) { /* ... */ }
});
// Upserts
Post::upsert([
['id' => 1, 'title' => 'Updated'],
['id' => 2, 'title' => 'New'],
], ['id'], ['title']);
```
## Form Requests
```php
class StorePostRequest extends FormRequest
{
public function authorize(): bool
{
return true; // Or use policies
}
public function rules(): array
{
return [
'title' => ['required', 'string', 'max:255'],
'content' => ['required', 'string'],
'published_at' => ['nullable', 'date'],
];
}
}
```
## Migrations
```php
return new class extends Migration
{
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('title');
$table->text('content');
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->index('published_at');
});
}
public function down(): void
{
Schema::dropIfExists('posts');
}
};
```
## Authorization (Policies)
```php
class PostPolicy
{
public function update(User $user, Post $post): bool
{
return $user->id === $post->user_id;
}
public function delete(User $user, Post $post): bool
{
return $user->id === $post->user_id || $user->is_admin;
}
}
// Usage in controller
$this->authorize('update', $post);
// Usage in Blade
@can('update', $post) ... @endcan
```
## Best Practices
1. **Use Form Requests** for validation, not controller logic
2. **Eager load relationships** to prevent N+1 queries
3. **Use policies** for authorization, not controller checks
4. **Type-hint dependencies** for automatic injection
5. **Use route model binding** instead of manual lookups
6. **Keep controllers thin** — move business logic to services/actions
7. **Use queued jobs** for slow operations (email, API calls)
## Laravel Boost
For AI-powered development, install Laravel Boost:
```bash
composer require laravel/boost --dev
php artisan boost:install
```
Provides MCP tools for inspecting routes, database, config, and more.
## References
For detailed docs, see `references/`:
- `controllers.md` — Controller patterns
- `eloquent.md` — Model conventions
- `routing.md` — Route definitions
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.