Download the PHP package divineomega/dates-timezone-conversion-trait without Composer
On this page you can find all versions of the php package divineomega/dates-timezone-conversion-trait. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download divineomega/dates-timezone-conversion-trait
More information about divineomega/dates-timezone-conversion-trait
Files in divineomega/dates-timezone-conversion-trait
Package dates-timezone-conversion-trait
Short Description Automatically convert an Eloquent model's dates to and from the current user's timezone
License LGPL-3.0-only
Informations about the package dates-timezone-conversion-trait
⏳🗺 Dates Timezone Conversion Trait
This package provides a trait that automatically converts an Eloquent model's dates to and from the current user's timezone.
Installation
Dates Timezone Conversion Trait can be easily installed using Composer. Just run the following command from the root of your project.
If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.
Usage
First, you must add a timezone
field to your application's main User
model and populate it with an appropriate timezone. Please see this list
of supported timezones.
Then, to benefit from this trait, simply use
it within any Eloquent Model.
An example of a User
model with the trait being used is shown below.
After using the trait, the following transformation will automatically be
applied to any attributes defined in the model's $dates
array, if a
user is currently logged in.
-
When reading an attribute (e.g.
$user->last_logged_in_at
), the datetime object will automatically be converted to the user's timezone. - When writing to an attribute (e.g.
$user->last_logged_in_at
), the datetime will automatically be converted to the Laravel application's timezone (as defined in theconfig/app.php
file).