laravel-dtos
Data Transfer Objects using Spatie Laravel Data. Use when handling data transfer, API requests/responses, or when user mentions DTOs, data objects, Spatie Data, formatters, transformers, or structured data handling.
Security Assessment
About laravel-dtos
The laravel-dtos skill focuses on providing a structured approach for handling data transfer in Laravel applications. It leverages the Spatie Laravel Data package to simplify the creation and manipulation of Data Transfer Objects (DTOs), a design pattern that helps encapsulate data. The primary goal of this skill is to avoid passing raw primitive values and instead use well-defined objects, ensuring clearer, more maintainable code. DTOs can be particularly useful when working with APIs, form requests, and data transformation tasks, providing consistency and improved type safety throughout your application.
FAQ
How do I use `::from()` with arrays?
You should always prefer using `::from()` with arrays where the keys match the constructor property names. This allows the package to handle automatic type casting based on the property types defined in your DTO.
Can I manually cast data when creating DTOs?
While you can manually cast data in some cases, it is generally not recommended. The `::from()` method is preferred as it automates type casting and simplifies your code.
Why should I avoid case mapper attributes?
Using case mapper attributes can introduce magic behavior that is difficult to trace. Instead, it's clearer and more maintainable to explicitly map field names in the calling code.
Is date casting handled automatically?
Yes, the Spatie Laravel Data package automatically casts date strings to `Carbon` or `CarbonImmutable` objects based on the property types in your DTO.
Who should use this skill?
This skill is ideal for developers working with Laravel applications who need to handle structured data, such as when managing API requests/responses, transforming data, or working with DTOs.
Install laravel-dtos
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
leeovery/claude-laravel