rawilk/laravel-casters
Collection of custom Eloquent cast classes for Laravel models. Add handy casts like Name to normalize and manipulate attributes automatically. Install via Composer; full docs available online.
$casts property to transform attributes during serialization/deserialization. This aligns perfectly with Laravel’s built-in casting system, reducing boilerplate and improving maintainability.Name, HasSingleNameColumn) that address common use cases like name manipulation, validation, and serialization. This is particularly valuable for applications with complex data transformation requirements (e.g., e-commerce, SaaS platforms with rich entity attributes).HasSingleNameColumn contract introduces a declarative way to define model behavior, promoting consistency and reducing magic in model implementations. This is a strong fit for teams adhering to SOLID principles or using domain-driven design (DDD).composer require rawilk/laravel-casters), and usage requires only defining casts in the $casts array. No database migrations or complex configurations are needed.Name cast).Accessors/Mutators) that could achieve similar goals with less risk?laravel-casters.User, Product) to test casts like Name or HasSingleNameColumn.Password cast (replaced by Laravel’s native hash cast).Name are designed not to store computed columns in the database, avoiding schema changes. However, verify that existing migrations align with the package’s assumptions (e.g., single-column names).composer require rawilk/laravel-casters.$casts arrays:
use Rawilk\LaravelCasters\Casts\Name;
protected $casts = [
'name' => Name::class,
];
HasSingleNameColumn contract.Password cast was deprecated in favor of Laravel’s native solution. Audit for similar future deprecations.where clauses on cast attributes).try {
$name = $model->name;
} catch (InvalidNameException $e) {
$name = 'Default Name';
}
composer why-not to detect conflicts and pin versions in composer.json.Name) and their benefits (e.g., consistent formatting).How can I help you explore Laravel packages today?