Laravel条件查询不起作用

时间:2017-10-05 04:57:25

标签: php laravel laravel-5 laravel-5.3

我的要求:我使用以下条件选择带有随机顺序的baseleads表

  1. beaseleads currentstatus列值具有新线索状态或

  2. beaseleads currentstatus列值具有 Call Not Picking 状态, updated_at 日期不等于Today Date

  3. 我的Laravel查询位于

    之下
    $baseleadsData=Baseleads::inRandomOrder()->Where('process_status',0)->where(function ($query) {
            $query->where('current_status','New Lead');
            $query->Orwhere('current_status','Call Not Picking');
    $query->OrwhereDate('updated_at', '!=', date('Y-m-d'));
        })->first();
    

    它没有正常工作。什么是我的错误。

3 个答案:

答案 0 :(得分:1)

->where(function ($query) {

        $query->where('current_status','New Lead')

              ->orWhere('current_status','Call Not Picking')

              ->orWhere('updated_at', '!=', date('Y-m-d').' 00:00:00');})->first();

答案 1 :(得分:0)

自从我使用Laravel以来已经有一段时间了,但你试过吗

  $query->where('current_status', '=', 'New Lead');
        $query->Orwhere('current_status', '=', 'Call Not Picking');

而不是

  $query->where('current_status','New Lead');
        $query->Orwhere('current_status','Call Not Picking');

我不确定这会有效,因为看起来Laravel会自动进行比较。你得到的错误代码是什么? (您可以在设置文件中打开调试模式)

答案 2 :(得分:0)

您需要在 camelCase 中使用方法名称 使用orWhereorWhereDate