Home>
Problem i am experiencing

When I use Laravel's Route :: resource, it generates a wrong route. I don't know what it is. How can I fix it?

https://readouble.com/laravel/5.7/en/controllers.html

Verb URI Action
GET admin/koumokus/{koumoku} show
GET admin/koumokus/{koumoku}/edit edit

should generate

Verb URI Action
GET admin/koumokus/{koumokus} show
GET admin/koumokus/{koumokus}/edit edit

has been generated. There is no problem for similar funrui.

Applicable source code
// routes/web.php
Route :: group (['prefix' =>'admin', 'as' =>'admin.', 'Namespace' =>'Admin', 'middleware' =>['verified']], function () {
    Route :: group (['prefix' =>'kouji', 'namespace' =>'Kouji', 'as' =>'kouji.'], Function () {
        // Construction classification
        Route :: delete ('funruis/destroy', 'FunruisController @ massDestroy')->name ('funruis.massDestroy');
        Route :: resource ('funruis', 'FunruisController');
        // Construction items
        Route :: delete ('koumokus/destroy', 'KoumokuController @ massDestroy')->name ('koumokus.massDestroy');
        Route :: resource ('koumokus', 'KoumokuController');
    });
});
Supplemental information (FW/tool version etc.)

Laravel 5.7
PHP 7.2
CentOS 7

  • Answer # 1

    Cannot convert to singular form in Laravel.

    >>>Str :: singular ('koumokus');
    =>"koumokus"

    Probably because it ends withus.

    https://github.com/doctrine/inflector/blob/90b2128806bfde671b6952ab8bea493942c1fdae/lib/Doctrine/Common/Inflector/Inflector.php#L174

    Simply use English as it is supported.

  • Answer # 2

    I wonder if the name of the controller is unpleasant (I wonder if Laravel isn't able to distinguish well, so it's a plural form)
    How about renaming withitemforkoumoku(item)?

  • Answer # 3

    Using words from sola-msr and kawax

    Route :: resource ('koumokus', 'KoumokusController', ['parameters' =>['koumokus' =>'koumoku']]);

    https://readouble.com/laravel/5.7/en/controllers.html
    Once you see the sights of the resource route parameters and set the parameters. A normal route was generated.