Skip to content
This repository was archived by the owner on Mar 3, 2025. It is now read-only.

Commit 2b13203

Browse files
committed
Update README
1 parent 55619ee commit 2b13203

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
[![Quality Score](https://img.shields.io/scrutinizer/g/jessarcher/laravel-castable-data-transfer-object.svg?style=flat-square)](https://scrutinizer-ci.com/g/jessarcher/laravel-castable-data-transfer-object)
66
[![Total Downloads](https://img.shields.io/packagist/dt/jessarcher/laravel-castable-data-transfer-object.svg?style=flat-square)](https://packagist.org/packages/jessarcher/laravel-castable-data-transfer-object)
77

8-
Laravel is awesome. Spatie's data transfer object package for PHP is awesome. They're already good friends, but now they're they're taking their relationship to the next level 💕
8+
Laravel is awesome. Spatie's [data transfer object](https://github.com/spatie/data-transfer-object) package for PHP is awesome. They're already good friends, but now they're they're taking their relationship to the next level 💕
99

10-
Have you ever wanted to cast your JSON columns to a value object? This package gives you a castable version of Spatie's `DataTransferObject` class, called `CastableDataTransferObject`.
10+
Have you ever wanted to cast your JSON columns to a value object?
11+
12+
This package gives you an extended version of Spatie's `DataTransferObject` class, called `CastableDataTransferObject`.
13+
14+
Under the hood it implements Laravel's [`Castable` interface](https://laravel.com/docs/8.x/eloquent-mutators#castables) with a Laravel [custom cast](https://laravel.com/docs/8.x/eloquent-mutators#custom-casts) that handles serializing between the `DataTransferObject` (or a compatible array) and your JSON database column.
1115

1216
Check out the blog post at https://jessarcher.com/blog/casting-json-columns-to-value-objects/
1317

@@ -21,7 +25,9 @@ composer require jessarcher/laravel-castable-data-transfer-object
2125

2226
## Usage
2327

24-
### 1. Create your `CastableDataTransferObject`:
28+
### 1. Create your `CastableDataTransferObject`
29+
30+
Check out readme for Spatie's [data transfer object](https://github.com/spatie/data-transfer-object) package to find out more about what their `DataTransferObject` class can do.
2531

2632
``` php
2733
namespace App\Values;
@@ -49,12 +55,14 @@ use Illuminate\Database\Eloquent\Model;
4955
class User extends Model
5056
{
5157
protected $casts = [
52-
'address' => Address::class
58+
'address' => Address::class,
5359
];
5460
}
5561
```
5662

57-
And that's it!
63+
And that's it! You can pass either an instance of your `Address` class, or even just an array with a compatible structure. It will automatically be cast to and from your class and JSON for storage.
64+
65+
Your data will be validated on the way in and out. But the best part is that you can decorate your class with domain-specific methods to turn it into a powerful value object.
5866

5967
### Testing
6068

0 commit comments

Comments
 (0)