我有以下路线组,里面有资源。
Route::group(array( 'prefix' => 'admin' , 'before' => 'admin-auth' ), function() {
Route::group(array( 'prefix' => 'hosts'), function() {
Route::resource('/', 'HostsController' );
});
});
正如我在php artisan routes
| GET /admin/hosts | admin.hosts...index | HostsController@index | admin-auth
| GET /admin/hosts/create | admin.hosts...create | HostsController@create | admin-auth
| POST /admin/hosts | admin.hosts...store | HostsController@store | admin-auth
| GET /admin/hosts/{} | admin.hosts...show | HostsController@show | admin-auth
| GET /admin/hosts/{}/edit | admin.hosts...edit | HostsController@edit | admin-auth
| PUT /admin/hosts/{} | admin.hosts...update | HostsController@update | admin-auth
| PATCH /admin/hosts/{} | | HostsController@update | admin-auth
| DELETE /admin/hosts/{} | admin.hosts...destroy | HostsController@destroy | admin-auth
如何拨打该路线的链接? 我尝试过像
这样的东西{{route('admin.hosts...show', array($host->id) )}}
但我收到array_combine()
错误。
我已经改变了。
Route::group(array( 'prefix' => 'admin' , 'before' => 'admin-auth' ), function() {
Route::resource('/hosts', 'HostsController' );
但我仍然得到一个双点路线名称。
GET /admin/hosts | admin..hosts.index | HostsController@index
GET /admin/hosts/create | admin..hosts.create | HostsController@create
POST /admin/hosts | admin..hosts.store | HostsController@store
GET /admin/hosts/{hosts} | admin..hosts.show | HostsController@show
GET /admin/hosts/{hosts}/edit | admin..hosts.edit | HostsController@edit
PUT /admin/hosts/{hosts} | admin..hosts.update | HostsController@update
PATCH /admin/hosts/{hosts} | | HostsController@update
DELETE /admin/hosts/{hosts} | admin..hosts.destroy | HostsController@destroy
现在我可以让它发挥作用但不是很奇怪吗?
答案 0 :(得分:2)
您托管的是您的/,那么您不需要为您的资源设置新组:
Route::group(array( 'prefix' => 'admin' , 'before' => 'admin-auth' ), function() {
Route::resource('hosts', 'UsersController' );
});
你会得到这样的东西:
+--------+-----------------------------------------------------+-------------------------------------------+-------------------------------------------------+----------------------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+-----------------------------------------------------+-------------------------------------------+-------------------------------------------------+----------------------------+---------------+
| | GET admin/hosts | admin.hosts.index | UsersController@index | admin-auth | |
| | GET admin/hosts/create | admin.hosts.create | UsersController@create | admin-auth | |
| | POST admin/hosts | admin.hosts.store | UsersController@store | admin-auth | |
| | GET admin/hosts/{hosts} | admin.hosts.show | UsersController@show | admin-auth | |
| | GET admin/hosts/{hosts}/edit | admin.hosts.edit | UsersController@edit | admin-auth | |
| | PUT admin/hosts/{hosts} | admin.hosts.update | UsersController@update | admin-auth | |
修改强>
此外,这是正确的路线:
Route::resource('hosts', 'UsersController' );
不是这一个:
Route::resource('/hosts', 'UsersController' );