|
1 | 1 | # Laravel Timezone
|
2 | 2 |
|
3 |
| -[](https://packagist.org/packages/jamesmills/laravel-timezone) |
4 |
| -[](https://packagist.org/packages/jamesmills/laravel-timezone) |
5 |
| -[](https://packagist.org/packages/jamesmills/laravel-timezone) |
6 |
| -[](https://scrutinizer-ci.com/g/jamesmills/laravel-timezone) |
7 |
| -[](https://github.styleci.io/repos/142882574) |
8 |
| -[](https://plant.treeware.earth/jamesmills/laravel-timezone) |
9 |
| -[](https://plant.treeware.earth/jamesmills/laravel-timezone) |
| 3 | +[](https://packagist.org/packages/jamesmills/laravel-timezone) |
| 4 | + |
| 5 | + |
| 6 | +[](https://plant.treeware.earth/jamesmills/laravel-timezone) |
| 7 | +[](https://plant.treeware.earth/jamesmills/laravel-timezone) |
10 | 8 |
|
11 | 9 | An easy way to set a timezone for a user in your application and then show date/times to them in their local timezone.
|
12 | 10 |
|
@@ -90,6 +88,31 @@ And with custom formatting
|
90 | 88 | // 2018-07-04 3:32 New York, America
|
91 | 89 | ```
|
92 | 90 |
|
| 91 | +### Using models casting class |
| 92 | + |
| 93 | +#### Basic usage |
| 94 | + |
| 95 | +``` |
| 96 | +<?php |
| 97 | +
|
| 98 | +namespace App; |
| 99 | +
|
| 100 | +use Illuminate\Database\Eloquent\Model; |
| 101 | +use JamesMills\LaravelTimezone\Casts\Timezone; |
| 102 | +
|
| 103 | +class Foo extends Model |
| 104 | +{ |
| 105 | + /** |
| 106 | + * The attributes that should be cast to native types. |
| 107 | + * |
| 108 | + * @var array |
| 109 | + */ |
| 110 | + protected $casts = [ |
| 111 | + 'created_at' => Timezone::class, |
| 112 | + ]; |
| 113 | +} |
| 114 | +``` |
| 115 | + |
93 | 116 | ### Saving the users input to the database in UTC
|
94 | 117 |
|
95 | 118 | This will take a date/time, set it to the users timezone then return it as UTC in a Carbon instance.
|
|
0 commit comments