所以,如果你做了像
这样的事情<table class="inline_sd_table"> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Accessories Optional</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Accommodates Ceiling Height</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ADA Compliance</b></td> <td class="inline_sd_even_cell">See Additional Information above</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Blower Air Mover Type</b></td> <td class="inline_sd_odd_cell">Fan</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Blower Included</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Boost Mode</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>CFM (Airflow)</b></td> <td class="inline_sd_even_cell">190</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Color/Finish</b></td> <td class="inline_sd_odd_cell">Almond</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Control Feature Filter Reminder</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Damper Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Delay Shut Off</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Digital Clock</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Dishwasher Safe Filters</b></td> <td class="inline_sd_even_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Duct Connector Size</b></td> <td class="inline_sd_odd_cell">3-1/4" x 10", 7" Round Non-Ducted</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>ENERGY STAR® qualified</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Filter Included</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Filter Type</b></td> <td class="inline_sd_even_cell">Aluminum</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Flue Accommodates ceilings up to xx ft</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Heat Sentry - Temperature Sensor</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>HVI Certified</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Light Bulb Quantity</b></td> <td class="inline_sd_even_cell">1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Light Bulbs Included</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Lighting Function</b></td> <td class="inline_sd_even_cell">One-level</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Lighting Type</b></td> <td class="inline_sd_odd_cell">Incandescent</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Max Sones/100 CFM</b></td> <td class="inline_sd_even_cell">4.1</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Minimum Height Above Cook Top</b></td> <td class="inline_sd_odd_cell">18"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Mounting Type</b></td> <td class="inline_sd_even_cell">Under Cabinet</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Nightlight</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Non-Stick Coated</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Depth (inches)</b></td> <td class="inline_sd_odd_cell">17-1/2"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Product Height (inches)</b></td> <td class="inline_sd_even_cell">6"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Product Width (inches)</b></td> <td class="inline_sd_odd_cell">42"</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Rated Amps</b></td> <td class="inline_sd_even_cell">2.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Remote Control</b></td> <td class="inline_sd_odd_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Horizontal Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Horizontal Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Rectangular High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Rectangular Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Sones Certified Vertical Round High</b></td> <td class="inline_sd_even_cell">6.5</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Sones Certified Vertical Round Low</b></td> <td class="inline_sd_odd_cell">N/A</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Switch Control Settings</b></td> <td class="inline_sd_even_cell">2</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>Switch Style</b></td> <td class="inline_sd_odd_cell">Rocker</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Timer</b></td> <td class="inline_sd_even_cell">No</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_odd_cell"><b>UL Listed</b></td> <td class="inline_sd_odd_cell">Yes</td> </tr> <tr class="inline_sd_cell_row"> <td class="inline_sd_even_cell"><b>Voltage</b></td> <td class="inline_sd_even_cell">120</td> </tr> </table>
所以在这一点上可以添加如下内容:
$ artisan make:model TurboClown
$ artisan make:controller TurboClownController -r --model=TurboClown
致Route::resource('clowns','TurboClownController');
。现在,当routes/web.php
与工匠合作时,我有clowns/{clown}
这样的路线。
但是,我的routes:list
功能就像:
show
当您 public function show(TurboClown $turboClown)
提出return $turboClown
作为回复时,当您请求&#34; / clowns / 3 /&#34;例如。我花了一段时间才弄清楚如果我将[]
参数更改为$turboClown
,我会得到一个JSON TurboClown作为回复。
所以从某种意义上说,我解决了我的问题。但我对几点感到好奇:
对我而言,https://laravel.com/docs/5.4/controllers#restful-naming-resource-route-parameters读起来好像我可以添加$clown
,然后['parameters' => ['clown' => 'turboClown']
可以使用&#34; turboClown&#34;,但它没有。< / p>
根据https://laravel.com/docs/5.4/routing#route-parameters:&#34;路由参数根据其顺序注入到路由回调/控制器中 - 回调/控制器参数的名称无关紧要。&#34;但看起来参数的名称在这种情况下确实很重要吗?
所以我正在寻找关于这两点的某种澄清,我错过了什么?
答案 0 :(得分:4)
参数数组应该是资源名称和参数名称的关联数组
因此,在您的情况下,资源名称是“clowns”(而不是“clown”),并且您希望此资源名称参数为“turboClown:
Route::resource('clowns', 'TurboClownController', ['parameters' => [
'clowns' => 'turboClown'
]]);
Laravel自动解析路径或控制器操作中定义的Eloquent模型,其类型提示的变量名称与路径段名称匹配。
对于这个非常酷的工作,参数必须匹配相应模型的标识符(在您的情况下为TurboClown
)。
所以现在结合这两点你应该能够做到这一点:
在路线档案中:
Route::resource('clowns', 'TurboClownController', ['parameters' => [
'clowns' => 'turboClown'
]]);
在TurboClownController
:
public function show(TurboClown $turboClown)
{
return $turboClown;
}
现在让我们假设您要检索标识符为5的turbo小丑。您可以对路线http://example.dev/clowns/5
进行校验。
希望它有所帮助。