healthengine / laravel-chronos
Swap out Carbon for Chronos
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- cakephp/chronos: ^2.2
- laravel/framework: ^10.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.26
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.3
This package is auto-updated.
Last update: 2024-08-28 00:08:15 UTC
README
Warning
This repository is archived. Use immutable date casts in laravel/framework instead.
Laravel Chronos
This is a custom package designed for Laravel Eloquent. It provides a trait that can be used in model classes that will cast datetime fields to ChronosInterface instead of Carbon instances.
Chronos is a drop-in replacement for Carbon but is immutable by default. It also provides an interface that can be used for some genericising as well.
See the Chronos documentation for more information.
Usage
Warning
This package is not compatible with Laravel's attribute casts: immutable_date, immutable_datetime.
To convert datetime casts from Carbon instances to Chronos instances in an Eloquent model, all you need to do is use
this trait in the model. An example is shown below:
use HealthEngine\LaravelChronos\ChronosTimestamps; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use ChronosTimestamps; protected $casts = [ // Throws error: "Call to undefined method Cake\Chronos\Chronos::toImmutable()" // 'processed_at' => 'immutable_date', // Throws error: "Call to undefined method Cake\Chronos\Chronos::toImmutable()" // 'processed_at' => 'immutable_datetime', 'processed_at' => 'datetime', ]; }
License
Laravel Chronos is licensed under the MIT license.