Eloquent Castable attributes are one of the more powerful features of Laravel; some people use them religiously while others tend to shy away from them. You can create a new Laravel project or use an existing one for this tutorial.
So now, if we wanted to extend this at all, we could: namespace App\Casts; use JessArcher\CastableDataTransferObject\CastableDataTransferObject; class Address implements CastableDataTransferObject { public string $nameOrNumber, public string $streetName, public string $localityName, public string $town, public string $county, public string $postalCode, public string $country, public function formatString(): string
namespace App\DataObjects; class Open { public function __construct( public readonly bool $monday, public readonly bool $tuesday, public readonly bool $wednesday, public readonly bool $thursday, public readonly bool $friday, public readonly bool $saturday, public readonly bool $sunday, public readonly array $holidays, ) {}}
Next, we can design our cast: namespace App\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class OpenDaysCast implements CastsAttributes { public function __construct( public readonly array $dates, ) {} public function set($model, string $key, $value, array $attributes)