定制 maartenpaauw/laravel-date-time-zone-cast 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

maartenpaauw/laravel-date-time-zone-cast

最新稳定版本:1.0.0

Composer 安装命令:

composer require maartenpaauw/laravel-date-time-zone-cast

包简介

A Laravel cast to convert strings to DateTimeZone instances

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel cast that allows you to store and retrieve DateTimeZone objects in your Eloquent models. This cast automatically converts timezone strings (e.g. 'Europe/Amsterdam') to PHP DateTimeZone instances and vice versa when interacting with your database.

Support Me

Model States for Filament

You can support me by buying Model States for Filament.

Installation

You can install the package via composer:

composer require maartenpaauw/laravel-date-time-zone-cast

Usage

1. Add the Cast to Your Model

Add the cast to your Eloquent model's $casts array:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Maartenpaauw\LaravelDateTimeZoneCast\DateTimeZoneCast;

class User extends Model
{
    protected $casts = [
        'timezone' => DateTimeZoneCast::class,
    ];
}

2. Database Schema

Ensure your database column is set up to store timezone strings:

Schema::table('users', function (Blueprint $table) {
    $table->string('timezone')->nullable();
});

3. Working with the Model

$user = new User();
$user->timezone = 'Europe/Amsterdam';
$user->save();

$timezone = $user->timezone; // DateTimeZone instance
echo $timezone->getName(); // 'Europe/Amsterdam'

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固