Backend Models

Define and configure Eloquent database models with relationships, casts, and validation.

Updated Nov 15, 2025
One-click install
npx skills add https://github.com/DevanB/lucidlog --skill backend-models-devanb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Backend Models
Source: https://github.com/DevanB/lucidlog/tree/main/.claude/skills/backend-models
Command: npx skills add https://github.com/DevanB/lucidlog --skill backend-models-devanb

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses the challenge of poorly defined or inconsistent database models, which can lead to data integrity issues, complex queries, and difficult-to-manage code. It guides the creation of well-structured Eloquent models with proper relationships, attributes, and validation, simplifying database interactions.

Core Features & Use Cases

  • Eloquent Relationships: Defines hasMany, belongsTo, etc., for clear data connections.
  • Data Integrity & Validation: Configures model attributes, casts, and validation rules to ensure data consistency.
  • Use Case: When creating a new Product model, use this skill to guide the AI in defining its attributes, setting up a hasMany relationship with an OrderItem model, and configuring casts for JSON fields, ensuring a robust and clear data structure.

Quick Start

Define a new 'Comment' backend model, including its relationships to 'User' and 'Post' models, and configure appropriate attributes.

Frequently Asked Questions about Backend 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 relationships like hasMany, belongsTo, and belongsToMany define connections between models. Configure them as methods in your model class to establish clear data associations, enabling simplified queries and maintaining referential integrity across your database structure.

What's the best way to structure database models with validation and casts?

Define models with proper attributes, configure casts for type conversion, set fillable or guarded properties, and apply validation rules. This ensures data consistency, prevents invalid entries, and simplifies attribute access throughout your application.

When do I need to configure timestamps, soft deletes, and model events?

Use timestamps to track creation and updates, soft deletes to preserve data while marking records inactive, and model events or observers to trigger actions on model lifecycle changes. These features handle common database patterns without custom logic.

Can I use factories and seeders to populate models during development?

Factories and seeders generate model instances for testing and development. Factories define attribute patterns, while seeders execute bulk insertions, letting you quickly populate databases with realistic test data.

How do I handle complex data types and JSON fields in models?

Configure casts to automatically serialize and deserialize JSON fields into arrays or objects. This simplifies working with complex nested data while maintaining type safety and reducing manual conversion code.