
Laravel Specialist
Generate and refactor Laravel Eloquent models, casts, accessors, and relationship definitions with framework-accurate PHP patterns.
Overview
laravel-specialist is an agent skill for the Build phase that teaches Laravel Eloquent model, cast, accessor, and relationship patterns in copy-paste PHP.
Install
npx skills add https://github.com/jeffallan/claude-skills --skill laravel-specialistWhat is this skill?
- Model blueprint with HasFactory, SoftDeletes, fillable, and array/boolean/datetime casts
- Laravel 9+ Attribute accessor/mutator syntax for title and computed excerpt
- Relationship recipes: hasMany, hasOne latestOfMany/oldestOfMany
- Copy-ready PHP namespaces under App\Models
Adoption & trust: 14.8k installs on skills.sh; 9.7k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your agent keeps producing outdated Laravel model code or wrong relationship helpers when you bootstrap a PHP API or SaaS backend.
Who is it for?
Solo builders on Laravel 9+ shipping CRUD-heavy SaaS or JSON APIs who want agent output to match framework conventions.
Skip if: Non-PHP stacks, Blade-only static sites, or teams that need full application architecture beyond the ORM slice in the readme.
When should I use this skill?
Scaffolding or refactoring Laravel Eloquent models, casts, accessors, or relationships in app/Models.
What do I get? / Deliverables
You get consistent App\Models classes with casts, Attribute accessors, soft deletes, and typed relationship methods ready for controllers and policies.
- Eloquent model classes with relationships
- Accessor/mutator Attribute definitions
Recommended Skills
Journey fit
How it compares
Focused Eloquent reference inside an agent skill—not a hosted Laravel SaaS boilerplate or generic SQL tutor.
Common Questions / FAQ
Who is laravel-specialist for?
Indie developers and small teams using AI coding agents to write Laravel backend models and relationships.
When should I use laravel-specialist?
During Build backend work when defining models, casts, accessors, or one-to-many relationships before wiring routes and tests.
Is laravel-specialist safe to install?
It is static PHP examples without embedded scripts—confirm trust via the Security Audits panel on this page before adding to your agent.
SKILL.md
READMESKILL.md - Laravel Specialist
# Eloquent ORM ## Model Patterns ```php <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Casts\Attribute; class Post extends Model { use HasFactory, SoftDeletes; protected $fillable = [ 'title', 'slug', 'content', 'published_at', 'user_id', ]; protected $casts = [ 'published_at' => 'datetime', 'metadata' => 'array', 'is_featured' => 'boolean', ]; // Accessor using new Attribute syntax (Laravel 9+) protected function title(): Attribute { return Attribute::make( get: fn (string $value) => ucfirst($value), set: fn (string $value) => strtolower($value), ); } // Mutator for computed property protected function excerpt(): Attribute { return Attribute::make( get: fn () => str($this->content)->limit(100), ); } } ``` ## Relationships ```php // One-to-Many class User extends Model { public function posts(): HasMany { return $this->hasMany(Post::class); } public function latestPost(): HasOne { return $this->hasOne(Post::class)->latestOfMany(); } public function oldestPost(): HasOne { return $this->hasOne(Post::class)->oldestOfMany(); } } class Post extends Model { public function user(): BelongsTo { return $this->belongsTo(User::class); } // Inverse relationship public function comments(): HasMany { return $this->hasMany(Comment::class); } } // Many-to-Many with Pivot class User extends Model { public function roles(): BelongsToMany { return $this->belongsToMany(Role::class) ->withPivot('expires_at', 'assigned_by') ->withTimestamps() ->using(RoleUser::class); // Custom pivot model } } // Has Many Through class Country extends Model { public function posts(): HasManyThrough { return $this->hasManyThrough(Post::class, User::class); } } // Polymorphic Relations class Image extends Model { public function imageable(): MorphTo { return $this->morphTo(); } } class Post extends Model { public function images(): MorphMany { return $this->morphMany(Image::class, 'imageable'); } } // Many-to-Many Polymorphic class Tag extends Model { public function posts(): MorphToMany { return $this->morphedByMany(Post::class, 'taggable'); } public function videos(): MorphToMany { return $this->morphedByMany(Video::class, 'taggable'); } } ``` ## Query Scopes ```php class Post extends Model { // Local scope public function scopePublished($query): void { $query->whereNotNull('published_at') ->where('published_at', '<=', now()); } public function scopePopular($query, int $threshold = 100): void { $query->where('views', '>=', $threshold); } // Global scope protected static function booted(): void { static::addGlobalScope('active', function ($query) { $query->where('status', 'active'); }); } } // Usage $posts = Post::published()->popular(500)->get(); // Custom Scope Class namespace App\Models\Scopes; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Scope; class AncientScope implements Scope { public function apply(Builder $builder, Model $model): void { $builder->where('created_at', '<', now()->subYears(10)); } } // Apply in model protected static function booted(): void { static::addGlobalScope(new AncientScope); } ``` ## Custom Casts ```php namespace App\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class Money implements CastsAttributes {