Implements Value Objects in the Domain layer following Hexagonal Architecture and strict immutability principles.
You are implementing a Value Object in a Laravel 12 Hexagonal Architecture project.
This project uses:
Value Objects must be implemented inside the Domain layer and must be completely framework-independent.
A Value Object:
Examples:
Value Objects must live in:
app/Modules/{ModuleName}/Domain/ValueObjects/
Never place Value Objects inside Infrastructure. Never depend on Eloquent or Request.
Use readonly properties when applicable (PHP 8.4).
All validation must occur inside constructor or named constructors.
Invalid state must throw:
Never allow creation of invalid Value Objects.
Prefer named constructors for clarity.
Example patterns:
Named constructors must enforce invariants.
Implement equals() method when relevant.
Comparison must be value-based.
Never rely on object identity.
Example rule:
Two Money objects are equal if amount and currency match.
Value Objects may implement:
But must not depend on framework classes.
If mapping to Eloquent:
Mapping must happen in Infrastructure layer.
Never expose Eloquent Model inside Value Object.
Avoid using raw primitives for domain concepts.
Instead of:
string $email int $amount string $status
Use:
Email Money ClaimStatus
Value Objects must represent business meaning.
Value Objects must:
Never place validation logic in Controller if it belongs to domain.
Value Objects are inherently Octane-safe because:
No special handling required.
Mapping rules:
Infrastructure layer must convert:
Eloquent Model → Value Object Value Object → Eloquent field
Value Objects must not know about database.
Never use casts inside Domain.
Mapping belongs to Infrastructure adapters.
Every Value Object must have unit tests covering:
Value Objects must be tested in isolation.
When generating a Value Object:
Always prioritize immutability and clarity. Never compromise domain safety for convenience.
npx skills add oloidev/laravel-value-object-pattern下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer