This library provides extended validation attributes, casts, transformers, and type utilities for spatie/laravel-data. It enhances the powerful data transfer object pattern with additional validation rules, type conversions, and utilities designed for Laravel 11+ with PHP 8.4+.
Requires PHP 8.4+ and Laravel 11+
Requires spatie/laravel-data 4.18+
composer require cline/data
- Validation Attributes - Comprehensive conditional and relational validation rules
- Casts and Transformers - Type conversion and data transformation utilities
- Type Utilities - Type coercion and conversion utilities (StringLike, BooleanLike, NumberLike)
- Examples - Real-world usage examples and patterns
use Cline\Data\Attributes\Validation\{PresentIf, MissingIf};
use Spatie\LaravelData\Data;
class OrderData extends Data
{
public function __construct(
#[PresentIf('type', 'premium')]
public ?string $upgradeOption = null,
#[MissingIf('automatic_renewal', true)]
public ?int $renewalDays = null,
) {}
}
use Cline\Data\Casts\{TrimCast, UpperCaseCast, NumberLikeCast};
use Spatie\LaravelData\Data;
class UserData extends Data
{
public function __construct(
#[TrimCast, UpperCaseCast]
public string $name,
#[NumberLikeCast]
public int $accountId,
) {}
}
use Cline\Data\Types\{StringLike, BooleanLike, NumberLike};
// Coerce values to appropriate types
$stringValue = StringLike::coerce('hello');
$boolValue = BooleanLike::coerce('true');
$numberValue = NumberLike::coerce('42.5');
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please use the GitHub security reporting form rather than the issue queue.
The MIT License. Please see License File for more information.