[Solved] resource controller, pass multiple parameters using AJAX


You can add that specific route above the resource (I’m assuming you are using GET for your ajax requests):

Route::group(array('prefix' => 'api/v1'), function(){
    Route::get('event/{start}/{end}', 'EventController@index');
    Route::resource('event', 'EventController');    
});

In your controller, make your parameters optional so you can use the same controller action for both routes, api/v1/event and api/v1/event:

<?php

class EventController extends BaseController {

    public function index($start = null, $end = null)
    {
        if (isset($start) && isset($end)) {
            return $this->eventsRepository->byDate($start, $end);
        }

        return $this->eventsRepository->all();
    }

}

If you want to be more specific about the start and end wildcards format, you can use where:

Route::get('event/{start}/{end}', 'EventController@index')
         ->where([
            'start' => 'regexp-here', 
            'end' => 'regexp-here'
           ]);

3

solved resource controller, pass multiple parameters using AJAX