Home > Software design >  RouteName and ModelName is same in Controller resource problem
RouteName and ModelName is same in Controller resource problem

Time:11-28

image_1

image_2

is there a way for the routeName (number 1) and modelName(number 2) to be different ?? (define both separately)

CodePudding user response:

You can tell Laravel to change the name wildcard by chaining on the the parameter() method:

Route::resource('article', ArticleController::class)->parameter('article', 'new_name');

The first argument is the current name (article) and the second parameter is the "new name".


In your case, since you want to change the route to "admin" but keep the name article for the wildcard, you should be able to do:

Route::resource('admin', ArticleController::class)->parameter('admin', 'article');

NB in the case of hyphenated routes, the 1st argument for parameter will actually be the snake-case version e.g.

Route::resource('foo-bar', FooBarController::class)->parameter('foo_bar', 'new_name');
  • Related