1

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?

Thisaru
  • 301
  • 3
  • 15
  • Does this answer your question? [How to route GET and POST for same pattern in Laravel?](https://stackoverflow.com/questions/18326030/how-to-route-get-and-post-for-same-pattern-in-laravel) – Tithira May 17 '21 at 05:25

3 Answers3

4

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', 'App\Http\Controllers\UserController@addView');
Route::post('/your-url', 'App\Http\Controllers\UserController@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

Gonzalo F S
  • 412
  • 3
  • 8
  • But ,If I'm not using the same route name for 2 ```get``` methods. one is for the ```post``` other is for the ```get```.it doesn't return any errors. is there a technical issue? – Thisaru May 17 '21 at 06:26
  • I'm not having any error.If this is technically wrong, what is the reason ? – Thisaru May 17 '21 at 06:35
  • 1
    @Thisaru maybe you are not using the naming? As Abdullah Shakir commented in its response to the same question, if you try to use the route by its name that should lead to an error or an undesired behaviour. Still, is a bad practice and I would suggest you to follow the documentation – Gonzalo F S May 17 '21 at 07:15
0

Actually you have same name for both routes i.e., name('user.add'). Change that.

Abdullah Shakir
  • 223
  • 2
  • 8
0

Yes you can get issues in future. For example, I had issues after functionality update - I've updated route interface (added some fields) and new fields does not appeared in result after opening URL. Please run command php artisan optimize to see is it all ok.