如何在laravel中的两个日期之间获取记录

时间:2017-09-15 06:06:22

标签: php laravel laravel-5 laravel-5.4

如何在不使用Query之间的laravel中获取两个日期之间的记录。

我使用以下查询来过滤记录。只有我发布带有数据的响应字段,过滤器才能获得正确的记录。从日期和日期发布时,它没有得到任何记录。这是我的错误..

 $q = Telecallerverification::query();

        $usersid = Auth::user()->id;

        $q->Where('created_by',$usersid);

        if ($request->input('frmdate_submit'))
        {
            $q->whereDate('created_at','<=',$request->input('frmdate_submit'));
        }

        if ($request->input('todate_submit'))
        {
            $q->whereDate('created_at','>=',$request->input('todate_submit'));
        }

        if ($request->input('response'))
        {
            $q->Where('leadsresponse',$request->input('response'));
        }

        $telecallerverifications = $q->orderBy('id','DESC')->paginate(25);

1 个答案:

答案 0 :(得分:1)

试试这个。希望它会对你有所帮助。

    $q = Telecallerverification::query();

    $usersid = Auth::user()->id;

    $q->Where('created_by',$usersid);

    if($request->input('frmdate_submit') && $request->input('todate_submit')){
       $q->whereBetween('created_at',array($request->input('frmdate_submit'),$request->input('todate_submit')))
   }
    else if ($request->input('frmdate_submit'))
    {
        $q->whereDate('created_at','<=',$request->input('frmdate_submit'));
    }

    else if ($request->input('todate_submit'))
    {
        $q->whereDate('created_at','>=',$request->input('todate_submit'));
    }

    else if ($request->input('response'))
    {
        $q->Where('leadsresponse',$request->input('response'));
    }

    $telecallerverifications = $q->orderBy('id','DESC')->paginate(25);