1

我有下面的路由组,里面有一个资源。

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

现在我可以让它工作,但这不是很奇怪吗?

4

1 回答 1

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' );
于 2013-11-05T12:01:10.613 回答