Ahmad Hilman
Ahmad Hilman

Reputation: 103

Handle post and get method in laravel 5.8

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

Answers (2)

Dhaval Naphade
Dhaval Naphade

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

fmsthird
fmsthird

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

Related Questions