php - Laravel-多个查询

标签 php twitter-bootstrap laravel sqlite

我试图在sqlite数据库上使用多个where查询,然后仅在两个日期ssDate和seDate之间选择查询。由于某种原因,当我知道两个日期之间有一个条目时,我什么也没有退回。

        if($status == "newOngoingClosed"){
        //dd($status, $ssDate, $seDate);
        $selStatus = Account::where('cActive', '=', 'New')
        ->orWhere('cActive', '=', 'Ongoing')
        ->orWhere('cActive', '=', 'Closed')
        ->whereBetween ('refDate', [$ssDate, $seDate])
        ->get();
        dd($selStatus);
        return view('reports_active')->withDetails($selStatus)->withQuery($status);
    }


任何帮助将不胜感激。

最佳答案

您的查询当前是:

select * 
from `accounts` 
where `cActive` = ? or `cActive` = ? or `cActive` = ? and `refDate` between ? and ?


请注意,最后一个条件是AND,这意味着它将选择在这些日期之间是新的,正在进行的或已关闭的事物

你需要:

Account::where([
      ['cActive', '=', 'New','or'] , 
      [ 'cActive', '=', 'Ongoing','or' ], 
      ['cActive', '=', 'Closed','or']
 ])->whereBetween ('refDate', [Carbon::now(), Carbon::now()])->get() //Note the carbons are just date placeholders , you can use your own


这将执行:

select * from `accounts` where (`cActive` = ? or `cActive` = ? or `cActive` = ?) and `refDate` between ? and ?

关于php - Laravel-多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50252976/

相关文章:

php类异常处理问题

php - 如何在 laravel 中对 json 对象进行排序

php - Laravel 5 Eloquent关系 "Has Many Through"SQL异常

php - 检查空值时出现问题

php - 与 Laravel faker 的嵌套关系 - laravel seeder

php - 如何在灯塔 graphql laravel 中获取自定义指令参数

jquery - 在 Bootstrap 中设置轮播位置

css - twitter bootstrap 并排对齐表格

css - pygments + Bootstrap : highlight shell code with dark background

php - Laravel-[PDOException] SQLSTATE[42S02] : Base table or view not found: 1146 Table 'ip.priorities' doesn't exist