Adjust timezone in each query from Laravel

1

I have developed a portal for a client and, at the last minute, he has asked me to adjust all the dates and times for foreign schedules.

Is there any way for MySQL to provide the translated date to another Timezone from Laravel?

I know the function convert_tz ) , what I'm looking for is a much more automated system in which I do not have to modify all my code.

    
asked by Programador Adagal 19.10.2016 в 09:40
source

1 answer

2

You can use the date mutators provided by laravel 5.2

link

link

When a column is considered a date in the model it is automatically parsed to an instance of Carbon, with this instance you can format the date to the format you want.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['user_date'];
}

By default the date format is this 'Y-m-d H: i: s'

Although you can change it directly with the attribute of the model class

protected $dateFormat = 'd-m-Y H:i:s';
    
answered by 19.10.2016 / 10:21
source