Laravel eloquent
Skill ComeOnOliver/skillshub/skills/HoangNguyen0403/agent-skills-standard/laravel-eloquent
π§ The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.
npx -y skills add ComeOnOliver/skillshub --skill laravel-eloquentAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
What its author says it does
Copied from the file, not written here
Advanced Eloquent ORM patterns for performance and query reuse. Use when working with Eloquent relationships, scopes, or advanced query optimization in Laravel. (triggers: app/Models/**/*.php, scope, with, eager, chunk, model)
SKILL.md
1.9 KB, as published. Nobody here has run it
Laravel Eloquent
Priority: P0 (CRITICAL)
Structure
app/
βββ Models/
βββ {Model}.php
βββ Scopes/ # Advanced global scopes
Implementation Guidelines
Query Efficiency & Performance
- N+1 Prevention: Always use
with()or$withfor relationships. Never access relationship properties in a loop without eager loading (N+1 Prevention). - Strict Loading: Call
Eloquent::preventLazyLoading(!app()->isProduction())inAppServiceProvider::boot()to throwLazyLoadingViolationExceptionin local/dev. - Large Datasets: Use
chunk(),lazy(), orcursor()for processing many records without memory issues (Memory Efficiency).
Query Logic & Scopes
- Reusable Scopes: Define
scopeName(Builder $query): Buildermethods in models for reusable query filters. - Chaining: Chain scopes (e.g.,
User::active()->verified()->get()) to keep controllers from duplicating query logic.
Models & Security
- Mass Assignment: Always define
protected $fillablearray; use$request->validated()forModel::create(). - Casting: Use
protected $castsfor dates, JSON, and custom types to ensure data consistency.
Anti-Patterns
- No lazy loading: Eager-load with
with()or$with; never in loops. - No business logic in Models: Move to Services or Actions.
- No raw SQL strings: Use Query Builder or Eloquent methods.
- No
select *: Specify required columns to limit data transfer.