laravel查询在本地和生产环境中不返回相同的结果

mqxuamgl  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(292)

我在我的web应用程序中使用laravel,问题是,我的本地机器和生产服务器有相同的数据,但是这个代码不返回相同的结果,为什么?

Table::whereRaw('Date(created_at) = CURDATE()')->where('column_1',$int)->where('column_2',$tring)->where('column_3','string')->first();

我认为这是可以的,但在我的服务器上总是空的(除非我在artisan-tinker中尝试)。
你能帮助我吗?
编辑:
表结构
样本数据
当我尝试此代码时:

$DayNBExist = Table::whereDate('created_at',date('Y-m-d'))->where(['profile_id'=>$id,'country'=>$country,'type'=>'user'])->first();

    if(!isset($DayNBExist->id)){

        Table::create([
            'nbr'=>1,
            'profile_id'=>$Channel->id,
            'country' => $country,
            'type' => 'channel',
        ]);

    }else{

        $DayNBExist->increment('nbr');

    }

它创建新行,而不是更新旧行。为什么?
谢谢所有的问题不是代码而是“$country”值

whlutmcx

whlutmcx1#

抱歉,我认为主要原因是 servertime 还有你的 localmachine 都不一样
请配置您的时间 'timezone' => 'UTC', 可以在

Project/config/app.php

或者有其他方法,但不推荐用于拉雷维尔
添加

date_default_timezone_set('Asia/Calcutta');

在index.php中(在公用文件夹中)

相关问题