Method controller does not exist.

泪湿孤枕 提交于 2019-12-06 14:17:43

As far as I'm aware that's never been available for Laravel 5. I haven't used 4 so I'm not sure about prior to 5. But in 5 you need to use Route::get and Route::post.

Route::get('datatables', ['as' => 'HomeController', 'uses' => 'HomeController@getIndex']);
Route::get('payments-data', ['as' => 'HomeControllerPaymentsData', 'uses' => 'HomeController@Payments']);

Yep, it was removed as using implicit controllers is bad practice - https://github.com/illuminate/routing/commit/772fadce3cc51480f25b8f73065a4310ea27b66e#diff-b10a2c4107e225ce309e12087ff52788L259

The controller method is deprecated since Laravel 5.3. But now, you can use the resource method, which is meant for the same purpose as the controller method:

From the docs:

Laravel resource routing assigns the typical "CRUD" routes to a controller with a single line of code. For example, you may wish to create a controller that handles all HTTP requests for "photos" stored by your application.

Use it as:

Route::resource('datatables', 'HomeController');

The downside of this implicit routing is that you have to name your methods consistently, more about it in the docs.

In most cases, better practise would be explicit routing, as it makes your code much more clear and understandable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!