Reputation: 103
let's say we make a route
Routes::post('article/save_comment','articleController@save_comment');
Then we call this route by typing URL in browser with post nothing, and of course, it will be error and says 'The GET method is not supported for this route. Supported methods: POST' cz if we call this URL directly Laravel knowing this as get method(correct me if I'm wrong)
and the question is how to handle this error? thanks
Upvotes: 2
Views: 330
Reputation: 579
You don't need to do that anymore to handle the error. add 404.blade.php in your resources/views/errors folder and Laravel will handle 404 errors for you. or you can use match route method instead of get
Route::match(['get', 'post'],article/save_comment','articleController@save_comment');
Upvotes: 0
Reputation: 1875
You can try this in the Exception handler #RenderMethod
if ($exception instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException) {
return response()->view('your-custom-error-view', []);
}
Upvotes: 2