[Vuejs]-Filtering the data on the basis of daterangepicker in laravel

0👍

You do not put any parameters to the server:

axios.get('/fetchdata', {
        params: {
            startDate: start.format('YYYY-MM-DD'),
            endDate: end.format('YYYY-MM-DD')
        }
    }).then(response => {
        data = this.form;
    });

Regarding AccessoryRequest, I guess you mean Accessory Eloquent object to work with the database

$accessory = AccessoryRequest::where('request_date', ">=", $request->startDate)->where('date', "<=", $request->endDate)->get(); //how can i filter

I am not sure how the name of the date field is, but idea is to do smth like

$accessory = AccessoryRequest::where('created_at', ">=", $request->get('startDate'))
    ->where('created_at', "<=", $request->get('endDate'))
    ->get();

0👍

In web.php —

Route::post('fetchdata', 'AccessoryController@fetch_data')->name('accessory.date.filter');

and in script file

 $(function () {
            $('input[name="daterange"]').daterangepicker({
            "startDate": "11/01/2021",
            "endDate": "11/07/2021"
            }, function(start, end, label) {
            console.log('New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')');
            axios.post('/fetchdata/', {
                        startDate: start.format('YYYY-MM-DD'),
                        endDate: end.format('YYYY-MM-DD'),
                    }).then(response => {
                        $(location).attr('href', '/accessory')
                        //console.log(startDate);
                    });
            });
        });

Axios was not working with get method.

Leave a comment