Alternative Route :: controller () in Laravel 5.3+

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

After updating when starting artisan serve I get:

 [BadMethodCallException] Method controller does not exist. 

I traced the problem to this piece of code in routes.php (now web.php )

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

This is the proposed query routing method for Documentation DataTables .

Was there an obsolete Route::controller() , and what is the alternative for these routes?

+5
source share
4 answers

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'); 
+7
source

I had the same problem as you, and none of the alternatives (explicit announcement or publication) was good enough. There were also some alternatives that required changing too much code.

That's why I wrote a class called AdvancedRoute, which serves as a replacement replacement.

It can be used by simply replacing the Route :: controller with AdvancedRoute :: as follows:

 AdvancedRoute::controller('users','UserController'); 

Full details on how to install and use the search in the GitHub repository at:

https://github.com/lesichkovm/laravel-advanced-route

I hope you find this helpful.

+5
source

https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0

The following features are deprecated in 5.2 and will be removed in release 5.3 in June 2016:

  • Implicit controller routes using Route::controller are deprecated. Please use explicit route accounting in the routes file. This will probably be extracted into the package.
+2
source

You can use resource ().

 Route::resource('users','UserController'); 

Note: the prefix "receive" is not required. getIndex() = index()

0
source

All Articles