控制器方法的替代品

时间:2017-04-14 08:56:22

标签: laravel-5.3

我在我的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'));


}

2 个答案:

答案 0 :(得分:0)

将路线写为:

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

此处帖子是您可以根据您的要求使用的方法类型。否则你可以使用资源

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

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

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

答案 1 :(得分:0)

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

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