且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 4-为用户设置时区

更新时间:2023-12-03 22:44:16

在文件app/filters.php中,

In the file app/filters.php,

执行此操作:

    App::before(function($request)
    {
        $timezone = (Auth::user()->userDetail->timezone) ? 
            Auth::user()->userDetail->timezone : 
            Config::get('app.timezone');
        date_default_timezone_set($timezone);

        DB::statement("SET time_zone = '" . $timezone . "'");
    });

作为奖励,我们设置了MySQL连接的时区.

As a bonus, we set the timezone of the MySQL connection.