我正在尝试使用与Laravel 5.1.19的REST-ful路由,但是我无法生成指向命名路由的链接并注入其参数。
这是我的routes.php
文件:
Route::resource('page', '\App\Http\Controllers\Admin\Page');
php artisan route:list
的输出:
+--------+----------+------------------------------+----------------------+---------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------------------------+----------------------+---------------------------------------------------------------+------------+
| | GET|HEAD | / | | Closure | |
| | GET|HEAD | _debugbar/assets/javascript | debugbar.assets.js | Barryvdh\Debugbar\Controllers\AssetController@js | |
| | GET|HEAD | _debugbar/assets/stylesheets | debugbar.assets.css | Barryvdh\Debugbar\Controllers\AssetController@css | |
| | GET|HEAD | _debugbar/clockwork/{id} | debugbar.clockwork | Barryvdh\Debugbar\Controllers\OpenHandlerController@clockwork | |
| | GET|HEAD | _debugbar/open | debugbar.openhandler | Barryvdh\Debugbar\Controllers\OpenHandlerController@handle | |
| | GET|HEAD | admin | | Closure | |
| | POST | page | page.store | \App\Http\Controllers\Admin\Page@store | |
| | GET|HEAD | page | page.index | \App\Http\Controllers\Admin\Page@index | |
| | GET|HEAD | page/create | page.create | \App\Http\Controllers\Admin\Page@create | |
| | PATCH | page/{page} | | \App\Http\Controllers\Admin\Page@update | |
| | PUT | page/{page} | page.update | \App\Http\Controllers\Admin\Page@update | |
| | DELETE | page/{page} | page.destroy | \App\Http\Controllers\Admin\Page@destroy | |
| | GET|HEAD | page/{page} | page.show | \App\Http\Controllers\Admin\Page@show | |
| | GET|HEAD | page/{page}/edit | page.edit | \App\Http\Controllers\Admin\Page@edit | |
+--------+----------+------------------------------+----------------------+---------------------------------------------------------------+------------+
所以我的理解是,如果我想链接到ID = 1的页面的Edit方法,我必须这样做:
<a href="{!! route('page.edit', ['page' => $page->id]) !!}">{{$page->title}}</a>
但是,当我将其放入刀片模板时,它会生成以下字符串:
http://localhost:8181/page//edit
(注意'page'和'edit'之间缺少的参数)
根据Artisan的输出,我应该提供一个'page'参数,我是,但它没有提起它。我究竟做错了什么?
谢谢!