Download the PHP package gnireeg/laravel-timezoned without Composer
On this page you can find all versions of the php package gnireeg/laravel-timezoned. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gnireeg/laravel-timezoned
More information about gnireeg/laravel-timezoned
Files in gnireeg/laravel-timezoned
Package laravel-timezoned
Short Description A lightweight Laravel package that provides a trait to automatically convert all date attributes of an Eloquent model from the database timezone to the user's timezone - and convert incoming user-provided dates back to the database timezone as well.
License MIT
Informations about the package laravel-timezoned
Laravel Timezoned
A lightweight Laravel package that automatically converts Eloquent model date attributes between the database timezone and the user's timezone.
- DB → User timezone when reading attributes
- User → DB timezone when writing attributes
This ensures consistent and intuitive date handling across different user timezones.
Installation
Optionally publish the config:
Usage
Reading Attributes
Writing Attributes
Raw Attribute Access
Configuration
The package config (config/timezoned.php) has two options:
Timezone Resolver
Determines the user's timezone. Receives the model instance as a parameter.
Database Timezone
The timezone your database stores dates in. Set to null to use config('app.timezone').
How It Works
The trait overrides two Eloquent methods:
getAttribute()- converts dates from database timezone to user's timezonesetAttribute()- converts dates from user's timezone to database timezone
Both Carbon and CarbonImmutable instances are supported.
Requirements
- PHP >= 8.1
- Laravel 10, 11, or 12
- Carbon >= 2
Testing
License
MIT
All versions of laravel-timezoned with dependencies
illuminate/support Version ^10.0 || ^11.0 || ^12.0
illuminate/database Version ^10.0 || ^11.0 || ^12.0
nesbot/carbon Version ^2.0 || ^3.0