{"enrichment":{"faq":[{"a":"eloquent-best-practices prevents N+1 queries by teaching eager loading with the `with()` method. Instead of loading relationships lazily (one query per record), load them upfront: `User::with('posts')->get()` fetches users and their posts in two queries total. Use `withCount()` for relationship counts without loading full records, and `load()` for lazy eager loading when needed. The skill covers detecting N+1 problems and restructuring queries for optimal database performance.","q":"How do I avoid N+1 queries in Laravel Eloquent?"},{"a":"eloquent-best-practices covers multiple optimization techniques: use eager loading (`with()`) to prevent N+1 queries, select only needed columns with `select()`, implement query scopes for reusable filters, chunk large datasets with `chunk()` to manage memory, leverage database indexes, and use `withCount()` instead of counting relationships manually. The skill emphasizes writing queries that execute at the database level rather than in PHP, reducing data transfer and processing overhead.","q":"What are the best practices for Eloquent ORM optimization?"},{"a":"eloquent-best-practices teaches relationship best practices including defining relationships correctly in models, using eager loading to fetch related data efficiently, understanding the difference between `with()` and `load()`, and avoiding lazy loading in loops. The skill covers one-to-many, many-to-many, and polymorphic relationships, showing how to structure queries to minimize database hits and improve application performance through proper relationship management.","q":"How should I manage Eloquent relationships properly?"},{"a":"eloquent-best-practices covers mass assignment protection using `$fillable` or `$guarded` properties, type casting with `$casts` for data safety, model events for automatic data handling, and query scopes for consistent filtering. The skill teaches how to protect against common vulnerabilities while maintaining code efficiency, ensuring your models are both secure and performant through proper Laravel conventions and patterns.","q":"What security and efficiency patterns should I implement in Laravel models?"},{"a":"eloquent-best-practices identifies key pitfalls: N+1 queries from lazy loading, selecting unnecessary columns, using `count()` instead of `withCount()`, chunking without proper ordering, and neglecting database indexes. The skill teaches recognizing anti-patterns like loading full relationships when only counts are needed, and provides concrete solutions for restructuring code to follow Eloquent best practices and maintain optimal database performance.","q":"What common Eloquent pitfalls should I avoid?"},{"a":"eloquent-best-practices teaches using `select()` to fetch only needed columns, reducing data transfer and improving speed. Combine with eager loading: `User::select('id', 'name')->with('posts:id,user_id,title')->get()`. The skill covers chunking large datasets to manage memory, using `withCount()` for aggregations, and leveraging database-level operations instead of PHP processing for faster queries and reduced server load.","q":"How do I select specific columns and optimize query performance?"}],"shadow_tags":["n-plus-one-prevention","database-performance","orm-optimization","relationship-loading","query-efficiency","memory-management","security-patterns","code-reusability","laravel-framework"],"summary_rewrite":"This skill teaches proven patterns for writing efficient Eloquent queries, from eager loading relationships to selecting only needed columns and using query scopes. Learn how to prevent common performance pitfalls like N+1 queries, implement mass assignment protection, and leverage database-level operations for faster data manipulation."},"files":[{"bytes":4724,"path":"skills/eloquent-best-practices/SKILL.md","sha256":"be57bc966399eada742f231f03e7f0a29bf3cc88385bba6b274c00a584ef94ce","url":"https://skillfed.io/files/iSerter/laravel-claude-agents/eloquent-best-practices/d21ed4ae/SKILL.md"}],"id":"iSerter/laravel-claude-agents/eloquent-best-practices","links":{"html":"https://skillfed.io/iSerter/laravel-claude-agents/eloquent-best-practices","md":"https://skillfed.io/iSerter/laravel-claude-agents/eloquent-best-practices.md","repo":"https://github.com/iSerter/laravel-claude-agents"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":8,"language":"PHP","last_updated":"2026-04-19","license":"MIT","name":"eloquent-best-practices","publisher":"iSerter","stars":41},"relations":{"similar":[{"id":"Jeffallan/claude-skills/laravel-specialist"},{"id":"AsyrafHussin/agent-skills/laravel-best-practices"},{"id":"rawveg/skillsforge-marketplace/laravel"},{"id":"personamanagmentlayer/pcl/php-expert"},{"id":"Pixel-Process-UG/superkit-agents/laravel-specialist"},{"id":"noartem/skills/laravel-prompting-patterns"},{"id":"iSerter/laravel-claude-agents/laravel-systematic-debugging"},{"id":"affaan-m/ECC/laravel-patterns"},{"id":"AsyrafHussin/agent-skills/laravel-database-optimization"},{"id":"iSerter/laravel-claude-agents/laravel-api-resource-patterns"}]},"slug":{"owner":"iSerter","repo":"laravel-claude-agents","skill":"eloquent-best-practices"},"version":"d21ed4ae"}
