Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在laravel中使用日期范围进行搜索_Php_Mysql_Laravel_Laravel 5.4 - Fatal编程技术网

Php 在laravel中使用日期范围进行搜索

Php 在laravel中使用日期范围进行搜索,php,mysql,laravel,laravel-5.4,Php,Mysql,Laravel,Laravel 5.4,我有一个db表dateprices id |巡演id |开始|结束|价格 我想获得从2017-06-20和2017-07-11这两个日期开始和结束的旅行的所有价格 我编写了以下查询,但它返回一个空集合: $dates = DatePrice::where('tour_id','=',$request->product_id) ->where('start', 'like', '%'.$request->start.'%') ->where('end', 'like

我有一个db表
dateprices

id |巡演id |开始|结束|价格

我想获得从2017-06-20和2017-07-11这两个日期开始和结束的旅行的所有价格

我编写了以下查询,但它返回一个空集合:

$dates = DatePrice::where('tour_id','=',$request->product_id)
  ->where('start', 'like', '%'.$request->start.'%')
  ->where('end', 'like', '%'.$request->end.'%')
  ->get();

我的查询有问题吗?

您应该像这样使用
whereBetween()
函数:

$dates = DatePrice::where('tour_id','=',$request->product_id)
    ->whereBetween('start', array('2017-06-20', '2017-07-11'))
    ->whereBetween('end', array('2017-06-20', '2017-07-11'))
    ->get();

您应该像这样使用
whereBetween()
函数:

$dates = DatePrice::where('tour_id','=',$request->product_id)
    ->whereBetween('start', array('2017-06-20', '2017-07-11'))
    ->whereBetween('end', array('2017-06-20', '2017-07-11'))
    ->get();
尝试下面的查询

如果只有一个条件,则可以使用用户
whereBetween()
。 如果要添加更多条件,可以使用
或wherebetween()

尝试下面的查询

如果只有一个条件,则可以使用用户
whereBetween()
。 如果要添加更多条件,可以使用
或wherebetween()


您可以通过指定列的名称(日期)进行搜索,如下所示


您可以通过指定列的名称(日期)进行搜索,如下所示


即使我将今天的日期作为开始日期,将明天的日期作为结束日期,查询也会给出表中的所有行。即使我将今天的日期作为开始日期,将明天的日期作为结束日期,查询也会给出表中的所有行。
$dates = DatePrice::where('tour_id','=',$request->product_id)
         ->whereBetween('date', array($request->from_date, $request->to_date))
         ->get();