PHP code example of brainlet-ali / laravel-convert-timezone

1. Go to this page and download the library: Download brainlet-ali/laravel-convert-timezone library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brainlet-ali / laravel-convert-timezone example snippets


use Brainlet\LaravelConvertTimezone\Traits\ConvertTZ;

class Post extends Model
{
    use ConvertTZ;
}

// That's it! All datetime fields now automatically convert to your configured timezone
$post = Post::first();
echo $post->created_at; // 2024-01-15 09:30:00 (in America/New_York instead of UTC)

// config/tz.php
'timezone' => env('TIMEZONE', 'America/New_York'),

$user = User::create(['email' => '[email protected]']);
echo $user->created_at; // Displays in your configured timezone, not UTC

public function getCreatedAtAttribute($value)
{
    // Your custom logic here
    return $value; // This will take precedence over timezone conversion
}
bash
php artisan vendor:publish --provider="Brainlet\LaravelConvertTimezone\TzServiceProvider" --tag="tz-config"