laravel-models

Guide Eloquent ORM model patterns, relationships, casts, and observers in Laravel.

Updated Sep 25, 2025
One-click install
npx skills add https://github.com/angelgarciasolorzano/social-hub --skill laravel-models-angelgarciasolorzano
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-models
Source: https://github.com/angelgarciasolorzano/social-hub/tree/main/.agents/skills/laravel-models
Command: npx skills add https://github.com/angelgarciasolorzano/social-hub --skill laravel-models-angelgarciasolorzano

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

This Skill unit provides a comprehensive guide to working with Eloquent models in Laravel, covering best practices, structure, relationships, casts, observers, concerns, and more, to help developers write clean, efficient, and maintainable database-driven code.

Core Features & Use Cases

  • Eloquent Model Patterns: Understand and implement Eloquent model patterns for database entities.
  • Casts & Relationships: Learn to define casts for type safety and establish various relationships between models.
  • Observers & Traits: Use observers for model lifecycle hooks and traits for reusable behavior.
  • Route Model Binding: Understand how to use route model binding for cleaner route definitions.
  • Mass Assignment Protection: Discover how to handle mass assignment safely in Eloquent models.
  • Timestamps & Soft Deletes: Learn to manage model timestamps and implement soft deletes.

Quick Start

Use the laravel-models skill to review the best practices for defining casts in your Eloquent models.

Frequently Asked Questions about laravel-models

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define Eloquent model relationships in Laravel?

Eloquent model relationships in Laravel are defined using methods like hasMany and belongsTo within your model classes. This guide covers establishing various relationships between database entities to ensure efficient data retrieval and clean code structure.

What is the best way to use Eloquent casts for type safety?

Eloquent casts provide type safety by automatically converting database attributes to common data types. This guide explains how to define casts in your Laravel models to ensure consistent data handling throughout your application.

How do Laravel model observers work for lifecycle hooks?

Laravel model observers group event hooks for multiple events into a single class, triggering actions during model lifecycle events like creation or updates. This guide demonstrates using observers to handle these lifecycle behaviors efficiently.

How do I handle mass assignment protection in Eloquent models?

Mass assignment protection in Eloquent models prevents unauthorized database updates by defining fillable or guarded properties. This guide shows how to safely handle mass assignment to secure your Laravel application's database interactions.

Do I need Laravel framework knowledge to use Eloquent ORM best practices?

Yes, implementing Eloquent ORM best practices requires Laravel framework knowledge and a basic understanding of Eloquent concepts. This guide targets developers aiming to build efficient database-driven applications within Laravel.

When should I use soft deletes in Laravel Eloquent models?

Soft deletes in Laravel Eloquent models should be used when you need to retain deleted records in your database while excluding them from standard queries. This guide covers managing timestamps and implementing soft deletes for data preservation.