laravel-value-objects

Creates immutable Laravel domain objects with factories and validation.

1|Updated Oct 10, 2025
One-click install
npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-value-objects
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-value-objects
Source: https://github.com/nextplus896/durra-alaseel/tree/main/.github/skills/claude-laravel/laravel-value-objects
Command: npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-value-objects

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Laravel applications often need robust representations of core domain concepts. This Skill provides a pattern to model domain values as immutable objects that encapsulate rules, ensure safe equality, and prevent unintended mutations across the system.

Core Features & Use Cases

  • Immutability with readonly properties to guarantee safe value semantics.
  • Static factory methods for expressive, intention-revealing construction.
  • Encapsulated domain logic: validation and behavior within the value object.
  • Common domain value examples: money, process result, coordinates, and email addresses.
  • Use Case: Represent monetary amounts with currency, perform calculations without mutating originals.

Quick Start

In a Laravel project, define a Money value object following the Money.php pattern under app/Values, then use Money::fromDollars(29.99) to create amounts and perform adds or multiplications as needed.

Frequently Asked Questions about laravel-value-objects

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

FAQPage Schema
How do I model domain concepts as immutable value objects in Laravel?

To model domain concepts as immutable value objects in Laravel, use readonly properties and static factory methods to encapsulate rules and ensure safe equality. This prevents unintended mutations across services for values like money or addresses.

What is the best way to represent money and currency safely in Laravel?

Representing money and currency safely in Laravel involves using a dedicated Money value object. This pattern encapsulates monetary amounts with currency, allowing you to perform calculations without mutating the original values.

How do I encapsulate domain validation rules inside Laravel models?

You encapsulate domain validation rules inside Laravel models by shifting logic into static factory methods on value objects. This ensures explicit validation and predictable behavior during construction rather than relying on external validation.

Does Laravel support readonly properties for domain modeling?

Laravel supports readonly properties for domain modeling through PHP's native features. Using readonly properties enforces immutability, guaranteeing safe value semantics and preventing unintended mutations across your application's services.

How do I perform calculations on monetary values without mutating the original data?

To perform calculations on monetary values without mutating the original data, use an immutable Money value object. Static factory methods create new instances for operations like additions or multiplications, ensuring the original amount remains unchanged.

Why does my domain logic behave unpredictably across services in Laravel?

Domain logic behaves unpredictably across services in Laravel when shared mutable objects are modified unintentionally. Applying immutable value objects with readonly properties prevents these side effects and ensures safe equality throughout the system.