I am using resource in laravel and i wanna a custom uri route for (show) action my route is:
Route::resource('/admin/users', 'UsersController')->except(['show']);
Route::get('/admin/users/{user}/show', 'UsersController@show')->name('users.show');
i checking a test url but not showing Error 404 in this Route for example :
http://127.0.0.1:8000/admin/users/test
show this error
The GET method is not supported for this route. Supported methods: PUT, PATCH, DELETE.
When I delete the code except(['show']) My code is working properly and shows a 404 error but my Route List Show Two Route for show action
| | GET|HEAD | backend/users/{user} | backend.users.show
| | GET|HEAD | backend/users/{user}/show | backend.users.show
I found the solution to this problem
Edit this file :
/app/Exceptions/Handler.php
Add this line
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
And
public function render($request, Throwable $exception)
{
if ($exception instanceof MethodNotAllowedHttpException)
{
abort(404);
}
return parent::render($request, $exception);
}