路由类型资源中方法的默认参数 Laravel 8
Default parameter for methods in routing type resource Laravel 8
我正在尝试根据文档将默认参数添加到资源路由:
我的代码如下:
Route::resource('flats', FlatsController::class)->parameters([
'index' => 'test_parameter',
'create' => 'test_parameter1',
'update' => 'test_parameter2'
]);
但不幸的是,在列出路由时,它总是像下面的屏幕截图所示:
请指点一下我哪里出错了?
您有以下内容:
| 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}
你只能将这个重命名为 per docs:
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 |
我正在尝试根据文档将默认参数添加到资源路由:
我的代码如下:
Route::resource('flats', FlatsController::class)->parameters([
'index' => 'test_parameter',
'create' => 'test_parameter1',
'update' => 'test_parameter2'
]);
但不幸的是,在列出路由时,它总是像下面的屏幕截图所示:
请指点一下我哪里出错了?
您有以下内容:
| 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}
你只能将这个重命名为 per docs:
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 |