0
votes

how to get records between two dates in laravel without using between Query.

I use following query for to filter a records. Only i post response field with data, filter is get correct records.when post from date and to date its not get any record.what's my mistake..

 $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

1 Answers

1
votes

Try this. Hope it will help you.

    $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);