laravel route uri bug

时间:2018-02-02 12:31:04

标签: php laravel routes

我试图使用:

Route::resource('categoria','CategoriaController');

当我查看控制器时,模型'Categoria'不会进入。然后我会查看:

php artisan route:list  

我看到以下路线:

POST      | categoria                                              | categoria.store               | Redebar\Http\Controllers\CategoriaController@store| web

GET|HEAD  | categoria/create                                       | categoria.create              | Redebar\Http\Controllers\CategoriaController@create                        | web          |

DELETE    | categoria/{categorium}                                 | categoria.destroy             | Redebar\Http\Controllers\CategoriaController@destroy                       | web          |

PUT|PATCH | categoria/{categorium}                                 | categoria.update              | Redebar\Http\Controllers\CategoriaController@update                        | web          |

GET|HEAD  | categoria/{categorium}                                 | categoria.show                | Redebar\Http\Controllers\CategoriaController@show                          | web          |

GET|HEAD  | categoria/{categorium}/edit                            | categoria.edit                | Redebar\Http\Controllers\CategoriaController@edit                          | web

--->"categoria/{categorium}"<-----

所以我做了一些测试,我发现字符串“ia”变成了“ium”。我写的例子:

galeria

laravel把它变成了:

galeria/{galerium}

为什么会发生这种情况,我该如何解决?

1 个答案:

答案 0 :(得分:1)

以下是本地化所需的内容:

// within AppServiceProvider's boot method
Route::resourceVerbs([
    'create' => 'crear',
    'edit' => 'editar',
]);

// register a resource 
Route::resource('fotos', 'PhotoController')

// and the output
/fotos/crear
/fotos/{foto}/editar

https://laravel.com/docs/5.5/controllers#restful-localizing-resource-uris

此外,您可以在使用资源路由时明确命名路由参数。

Route::resource('user', 'AdminUserController', ['parameters' => [
    'user' => 'admin_user'
]]);

https://laravel.com/docs/5.5/controllers#restful-naming-resource-route-parameters