Skip to content
Advertisement

Laravel Duplicate Route names

I’m using same route name for the get & post methods in route. those routes are using for the same purpose. ex : I’m calling to load add view form using get route

Route::get('add', 'UserController@addView')->name('user.add'); then,

I’m calling to store data in that form using post route

Route::post('add', 'UserController@store')->name('user.add');

is there any issue , If I use the same route name like this?

Advertisement

Answer

No, you can not use the same name for 2 different routes as is stated in the documentation if you really need to name the routes you should look for different names, but if there’s no need to have named routes you can have each url with its method like:

Route::get('/your-url', 'AppHttpControllersUserController@addView');
Route::post('/your-url', 'AppHttpControllersUserController@store');

If you are making a CRUD you can have:

Route::resource('user', UserController::class);

This will create all the urls needed for a CRUD:

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement