jord-jd/dates-timezone-conversion-trait 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jord-jd/dates-timezone-conversion-trait

最新稳定版本:v3.0.0

Composer 安装命令:

composer require jord-jd/dates-timezone-conversion-trait

包简介

Automatically convert an Eloquent model's dates to and from the current user's timezone

README 文档

README

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 jord-jd/dates-timezone-conversion-trait

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.

<?php

namespace App\Models;

use JordJD\DatesTimezoneConversion\Traits\DatesTimezoneConversion;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable, DatesTimezoneConversion;

    protected $dates = [
        'last_logged_in_at',
        'created_at',
        'updated_at'
    ];

    /* snipped */
}

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 the config/app.php file).

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2026-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固