Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit 05de471

Browse files
committed
update readme
1 parent 5805937 commit 05de471

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ You can generate a Snowflake by resolving the service out of the container and c
6262
resolve('snowflake')->id(); // (string) "5585066784854016"
6363
```
6464

65-
> **WARNING**: Do not create instances of the Snowflake service, as doing so risks generating matching keys / introducing collisions. Instead, always resolve the Snowflake singleton out of the container. You can also use the global helper method (see below).
65+
> **WARNING**: Do not create instances of the Snowflake service, as doing so risks generating matching keys / introducing collisions. Instead, always resolve the Snowflake singleton out of the container. You can also use the global helper method (see below).
6666
6767
Since this is a little cumbersome, the package also registers a global `snowflake()` helper method that you can use anywhere.
6868

@@ -117,6 +117,30 @@ class User extends Model
117117
}
118118
```
119119

120+
#### Optional casting
121+
122+
The package also includes a custom `SnowflakeCast` that will automatically handle conversion from `string` to `integer` and vice-versa when storing or fetching a Snowflake from the database. If you wish, you may use this cast for any model attribute that will contain a Snowflake e.g.
123+
124+
```php
125+
<?php
126+
127+
namespace App\Models;
128+
129+
use Snowflake\Snowflakes;
130+
use Snowflake\SnowflakeCast;
131+
132+
class Post extends Model
133+
{
134+
use Snowflakes;
135+
136+
protected $casts = [
137+
'id' => SnowflakeCast::class,
138+
'user_id' => SnowflakeCast::class,
139+
'title' => 'string',
140+
];
141+
}
142+
```
143+
120144
## Contributing
121145

122146
Thank you for considering a contribution to Snowflake. You are welcome to submit a PR containing improvements, however if they are substantial in nature, please also be sure to include a test or tests.

0 commit comments

Comments
 (0)