Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/divineomega/dates-timezone-conversion-trait
⏳🗺 Automatically convert an Eloquent model's dates to and from the current user's timezone
https://github.com/divineomega/dates-timezone-conversion-trait
eloquent laravel timezone timezone-conversion trait
Last synced: 3 months ago
JSON representation
⏳🗺 Automatically convert an Eloquent model's dates to and from the current user's timezone
- Host: GitHub
- URL: https://github.com/divineomega/dates-timezone-conversion-trait
- Owner: DivineOmega
- License: lgpl-3.0
- Created: 2018-10-09T23:32:34.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-11T07:37:34.000Z (almost 6 years ago)
- Last Synced: 2024-10-15T02:39:25.800Z (4 months ago)
- Topics: eloquent, laravel, timezone, timezone-conversion, trait
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 23
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⏳🗺 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.```
composer require divineomega/dates-timezone-conversion-trait
```If you have never used the Composer dependency manager before, head
to the [Composer website](https://getcomposer.org/) 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](https://secure.php.net/manual/en/timezones.php).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.```php
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 the `config/app.php` file).