'How to stop the GET method is not supported for this route from showing?

I have a working Laravel project with loads of different routes.

I'm currently testing it and one of my tests was to check if a user were to use a delete or post route from the URL. I didn't know what the application would do honestly and it outputted the typical:

The GET method is not supported for this route. Supported methods: DELETE

which I have seen a million times. Is there a way to stop this error from coming up and instead output an error screen or simply redirect to a different view?



Solution 1:[1]

The error message:

The GET method is not supported for this route. Supported methods: DELETE.

should only appear when your Laravel site has APP_DEBUG set to true (in the .env file).

When APP_DEBUG is set to false as it should always be in on a live site, then the user will be shown a 404 error page instead.


You can easily test this by adding the following code to your routes file:

Route::delete('test', function() {
    return 'You should never see this text when viewing url via a GET request';
});

Solution 2:[2]

May be u didn't noticed but ur form tag method attribute and route definition is different

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 VANITA CHAUDHARI