2

我正在尝试根据文档将默认参数添加到资源路由:

Laravel 文档

我的代码如下所示:

Route::resource('flats', FlatsController::class)->parameters([
    'index' => 'test_parameter',
    'create' => 'test_parameter1',
    'update' => 'test_parameter2'
]);

但不幸的是,在列出路由时,它总是像下面的屏幕截图所示:

路由表

请帮助指导我在什么时候犯了错误?

4

1 回答 1

1

您有以下内容:

| Methods   | route                               |
|-----------|-------------------------------------|
| POST      | panel/investments/flats             |
| GET/HEAD  | panel/investments/flats             |
| GET/HEAD  | panel/investments/flats/create      |
| GET/HEAD  | panel/investments/flats/{flat}      |
| PUT/PATCH | panel/investments/flats/{flat}      |
| DELETE    | panel/investments/flats/{flat}      |
| GET/HEAD  | panel/investments/flats/{flat}/edit |

由于唯一的参数是{flat}您只能根据文档重命名此参数:

Route::resource('flats', FlatsController::class)->parameters([
    'flat' => 'apartment'
]);

这导致:

| Methods   | route                                    |
|-----------|------------------------------------------|
| POST      | panel/investments/flats                  |
| GET/HEAD  | panel/investments/flats                  |
| GET/HEAD  | panel/investments/flats/create           |
| GET/HEAD  | panel/investments/flats/{apartment}      |
| PUT/PATCH | panel/investments/flats/{apartment}      |
| DELETE    | panel/investments/flats/{apartment}      |
| GET/HEAD  | panel/investments/flats/{apartment}/edit |
于 2021-06-02T07:57:42.670 回答