Question

I have the below route group with a resource inside.

Route::group(array( 'prefix' => 'admin' , 'before' => 'admin-auth' ), function() {

   Route::group(array( 'prefix' => 'hosts'), function() {

        Route::resource('/', 'HostsController' );

   });
});

As I've seen in the 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

How can I call the link to the route? I've tried something like

{{route('admin.hosts...show', array($host->id) )}}

But I get a array_combine() error.

Edit

I've changed to this.

Route::group(array( 'prefix' => 'admin' , 'before' => 'admin-auth' ), function() {

    Route::resource('/hosts', 'HostsController' );

but still I get a double dotted route name.

 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

Now I can make it work but isn't it kind of weird?

Was it helpful?

Solution

You hosts is your /, then you don't need a new group for your resources:

Route::group(array( 'prefix' => 'admin' , 'before' => 'admin-auth' ), function() {

   Route::resource('hosts', 'UsersController' );

});

And you'll get something like this:

+--------+-----------------------------------------------------+-------------------------------------------+-------------------------------------------------+----------------------------+---------------+
| 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                 |               |

EDIT

Also, this is the right route:

Route::resource('hosts', 'UsersController' );

Not this one:

Route::resource('/hosts', 'UsersController' );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top