laravel-data-writer

Create Spatie Laravel Data classes with constructor promotion and annotation-based validation.

Updated Nov 18, 2025
One-click install
npx skills add https://github.com/RasmusGodske/claude-code-agent-communication --skill laravel-data-writer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-data-writer
Source: https://github.com/RasmusGodske/claude-code-agent-communication/tree/main/.claude/skills/laravel-data-writer
Command: npx skills add https://github.com/RasmusGodske/claude-code-agent-communication --skill laravel-data-writer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Creating and maintaining Laravel Data classes (Spatie) can be verbose and error-prone when properties are not promoted in the constructor, and when validation is missing or implemented via manual rules. This Skill standardizes the pattern across projects, ensuring constructor property promotion, annotation-based validation, and consistent data organization.

Core Features & Use Cases

  • Enforces constructor property promotion for all Data classes to improve readability and reliability.
  • Encourages annotation-based validation (Required, StringType, Email, etc.) and supports optional fields, collections, enums, and PHPDoc typing.
  • Guides data organization by usage context (e.g., API controllers, Inertia props, MCP tools) with nested directories for clarity and reuse.
  • Facilitates optional TypeScript export when frontend types are needed.

Quick Start

  • Create a new Data class named UserData that uses constructor property promotion, includes public string $name and public string $email with Required validation annotations, and place it under app/Data/Http/Controllers/Api/UserController/UserData.php. Then reference this Data class from your controller or API response as App\Data\Http\Controllers\Api\UserController\UserData.

Frequently Asked Questions about laravel-data-writer

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

FAQPage Schema
How do I create Laravel Data classes with constructor property promotion and annotation validation?

To create Laravel Data classes with constructor property promotion, define public properties directly in the constructor parameters and apply Spatie annotation-based validation attributes like Required or Email to each property. This approach ensures clean, readable, and validated data objects.

What's the best way to organize Spatie Laravel Data classes for APIs and Inertia props?

Organize Spatie Laravel Data classes by grouping them into nested directories based on their usage context, such as API controllers or Inertia props. Placing files under paths like app/Data/Http/Controllers/Api/ ensures clear structure and easy reuse across your Laravel project.

Can I export TypeScript types from Spatie Laravel Data objects?

Yes, you can export TypeScript types from Spatie Laravel Data objects. The skill facilitates optional TypeScript export when frontend types are needed, allowing your Laravel data models to seamlessly integrate with TypeScript-based frontend architectures.

How do I handle collections and enum casts in Laravel Data classes?

Handle collections and enum casts in Laravel Data classes by utilizing DataCollections for list properties and applying enum casts where needed. This ensures type safety and consistent data mapping when dealing with multiple records or enumerated values.

Does Laravel Data support PHPDoc typing alongside constructor promoted properties?

Yes, Laravel Data supports PHPDoc typing alongside constructor promoted properties. Combining constructor property promotion with PHPDoc typing enhances IDE autocompletion and static analysis while maintaining concise and reliable data class definitions.