samedi 9 janvier 2021

How can I filter dates between start and end using query builder wherebetween

I have put two input tag to get the start date and end date. I want to use the wherebetween clause of laravel query builder to take in those inputs and get back data between those two days

blade.php file

<form action="" method="POST">
                    @csrf
                    <h3 style="color:Blue; text-align: center;text-decoration:underline"><b>Filter Date </b></h3>
                    <input class="form-control" type="text" id="datepicker1" name="start_date" placeholder="Start Date" style="width: 20%; display: inline-block; margin-left:20%; margin-bottom: 2% ">
                    <input class="form-control" type="text" id="datepicker2" name="end_date" placeholder="End Date" style="width: 20%; display: inline-block; margin-left:20%; margin-bottom: 2%">
                    <br>
                    <button type="submit" class="btn btn-success" style="position: absolute;
                    left: 45%;">Find Expenses</button>
                </form>

Script

<script>
$( function() {
    $( "#datepicker1" ).datepicker({
        dateFormat: 'dd-mm-yy'
    });
} );
$( function() {
    $( "#datepicker2" ).datepicker({
        dateFormat: 'dd-mm-yy'
    });
} );
</script>

Controller

public function search_between_dates(Request $request,$exp_category_id){
    $start_date = dmyToYmd($request->start_date);
    $end_date = dmyToYmd($request->end_date);

    $expense_category_data = DB::table('expense_category')
                    ->leftjoin('expense_table','expense_category.id','=','expense_table.exp_category')
                    ->select('expense_category.id as category_id','expense_category.exp_category AS category_name','expense_category.exp_category_details','expense_category.exp_category_image','expense_table.*')
                    ->where('expense_category.id',$exp_category_id)
                    ->whereBetween('expense_table.exp_date',[date($start_date),date($end_date)])
                    ->get();                        
    return view('admin.Expense_sheet.view_expense_category_details',compact('expense_category_data'));
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire