dongweiben5229 2016-04-03 17:56
浏览 72
已采纳

Laravel中的高级条款

I have an issue with my query in Laravel eloquent, I do not get results when I run the query and the generated query does not seem to be what I expect.

This is the code in controller:

$lastUpdate = Input::get('last_update');
$userId = Auth::user()->id;

$eventIds = EventVendor::where('user_id', $userId)
                    ->where('is_active', 1)->get()->lists('event_id');

$events = EventDetails::whereIn('id', $eventIds)
                    ->where(function($query) use ($lastUpdate) {
                        $query->where('created_at', $lastUpdate);
                        $query->orWhere('updated_at', $lastUpdate);
                    })
                    ->where('is_active', 1)
                    ->with("details_sub")
                    ->with("extras")
                    ->with("chargesDiscounts")
                    ->toSql();

This is the query that is generated:

select * from `mtgh_event_details` 
    where `mtgh_event_details`.`deleted_at` is null 
        and 0 = 1 
        and (`created_at` = ? or `updated_at` = ?) 
        and `is_active` = ?

Apart from the 0 = 1 which isn't supposed to be in there I do not see the full query either.

  • 写回答

2条回答 默认 最新

  • dongpalou5352 2016-04-03 19:09
    关注

    So i found the issue, apparently this part of the query

    $eventIds = EventVendor::where('user_id', $userId)
                        ->where('is_active', 1)->get()->lists('event_id');
    

    Was returning null or an empty list, hence the 0 = 1 in my query. Also with the help of the other answer I was able to simplify my code a bit so thanks. :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作