Search code examples
laravelrouteslaravel-5.3

Route::controller() alternative in Laravel 5.3+


I just upgraded from Laravel 5.2 to 5.3. I am using Laravel-DataTables package for several tables in my application.

After upgrade when I run artisan serve I'm receiving:

[BadMethodCallException]
Method controller does not exist.

I've tracked the issue down to this piece of code in my routes.php (now web.php)

Route::controller('datatables', 'ProfileController', [
    'anyOrders'  => 'datatables.dataOrders',
    'anyProperties' => 'datatables.dataProperties',
]);

This is the suggested way to route the queries for DataTables Documentation.

Was the Route::controller() deprecated, and what is the alternative to for these routes?


Solution

  • The explicit routes will be:

    Route::get('/datatables/orders', array('middleware' => 'auth', 'uses' => 'ProfileController@anyOrders'))->name('datatables.dataOrders');
    Route::get('/datatables/properties', array('middleware' => 'auth', 'uses' => 'ProfileController@anyProperties'))->name('datatables.dataProperties');