控制器方法的替代方案

alternatives of controller method

我在我的laravel 5.3项目中使用这段代码,但它说它是badcallmethodexception,我发现控制器方法在新版本中不再可用,如何编写这段代码? 这是我的代码:

Route::controller('notifications', 'NotificationController');

在这个控制器里面有这个代码:

public function getIndex()
{
    return view('notification');
}

public function postNotify(Request $request)
{
    $notifyText = e($request->input('notify_text'));


}

将路线写为:

Route::post('notification','NotificationController@method-name');

此处post是您可以根据需要使用的方法类型。或者你可以使用资源作为

Route::resource('notification','NotificationController');

资源只能用于索引、创建、存储、更新和销毁方法。

Laravel 文档:https://laravel.com/docs/5.3/controllers#resource-controllers

如果您没有使用默认的 laravel 控制器方法,您需要定义应该为路由调用的方法。

Route::get('notifications', 'NotificationController@getIndex');
Route::post('notifications', 'NotificationController@postNotify');