Chron
1 month ago
195
2
Laravel

Is there a way to prevent user from accessing non-GET routes?

Posted 1 month ago by Chron

For example, I have these routes:

Route::post('user','[email protected]')->name('user.store');
Route::get('user/create','[email protected]')->name('user.create');
Route::get('user/{user}/edit','[email protected]')->name('user.edit');
Route::patch('user/{user}','[email protected]')->name('user.update');
Route::delete('user/delete','[email protected]')->name('user.destroy');

When I visit the /user which is a post route, I get an error:

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

Is there a way to prevent the user from accessing these routes instead of just throwing an error? Maybe navigate back if its not a get route.

Please sign in or create an account to participate in this conversation.