copain
1 year ago
226
5
Laravel

Date search in Laravel 5.5

Posted 1 year ago by copain

i have a table with 3 search functions, [1.search box, 2.drop-down 3. date-picker] now i'm having problem with (date-picker) how do i make it work inside my controller i want to have like Date_From and Date_To so i can filter the date, but in my DB i only have the default timestamp which is the created_at column is it possible to use it? and how?

Note: Search box and drop down search is working fine with this code, all i need is the code for date search and where to put it inside my controller and blade.

CONTROLLER:


 public function index(Request $request)
    {
     
        $search=$request->input('search'); 
      

        if(request()->has('lead_status')){
            $leads=Lead::where('lead_status', request('lead_status'))
            ->paginate(5)
            ->appends('lead_status',request('lead_status'));
        }
    
        else{

            $leads=Lead::orderBy('created_at','desc')->search($search)->paginate(5);
      
        }

        return  view ('leads.index')->with('leads',$leads);
    
    }



View.Blade


<form action="{{route('leads.index')}}" method="get" class="form-inline" >
 <!--Start Search Box -->
    <div class="form-group">

    <input type="text" name="search" class="form-controll" placeholder="Enter Name" value=" 
    {{isset($search) ? $search : ''}}" style="text-transform:uppercase;" >

    </div>

    <div class="form-group">

    <button type="submit"><i class="fa fa-search"></i></button>

    </div>
    <!--End Search Box -->

     <!--Start Drop Down Filter -->

    <div class="form-group">
     <div class="dropdown">
        <button class="dropbtn">Select Status <i class="fa fa-caret-down"></i></button>
          <div class="dropdown-content">
          <a href="/leads?lead_status=enrolled">ENROLLED</a>
          <a href="/leads?lead_status=pending">PENDING</a>
          <a href="/leads?lead_status=cancel">CANCEL</a>
           
      </div>
   </div>

    <!--End Drop Down Filter -->

  <!--Start Date Picker-->


<div class="form-group">
   <label>FROM</label>
   <input type="date"  name="from" value="" class="form-control" >

    <label>TO</label>
   <input type="date"  name="to" value="" class="form-control" >

   <div class="form-group">
    <button type="submit"><i class="fa fa-search"></i></button>
    </div>                   
   </div>

  <!--End Date Picker-->



    </form>

Please sign in or create an account to participate in this conversation.