Laravel Value Objects is a fantastic package that offers a bunch of general-purpose value objects you can use in your Laravel application. You can generate custom value objects with the Artisan command: php artisan make:value-object YourNameValueObject Boolean $bool = new Boolean('1'); $bool = Boolean::make('1'); $bool = Boolean::from('1'); $bool->value(); // true (string) $bool; // 'true' $bool->toArray(); // ['true']
Text $text = new Text('Lorem Ipsum is simply dummy text.'); $text = Text::make('Lorem Ipsum is simply dummy text.'); $text = Text::from('Lorem Ipsum is simply dummy text.'); $text->value(); // 'Lorem Ipsum is simply dummy text.' (string) $text; // 'Lorem Ipsum is simply dummy text.'