1

I am trying to add Route::group() based on a users role.

Route::group(['middleware' => ['role:myrole']], function () {
    //Some Routes
}

I am getting this error...

Missing argument 3 for Zizaco\Entrust\Middleware\EntrustRole::handle()

I have the default install for Entrust. I am told that I need to add a line or two to the Kernel.php file in '$middlewareGroups'

What are the lines?

jszobody
  • 28,495
  • 6
  • 61
  • 72
maddog_94
  • 21
  • 4

2 Answers2

1

You're looking for these I think:

'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,

Note, I have them in $routeMiddleware

Then assign your roles/permissions however you see fit to a group or individual route. But store them in $routeMiddleware. For example:

Route::group(['middleware' => ['role:admin|owner']], function () { .. });

Mike Barwick
  • 6,288
  • 6
  • 51
  • 76
  • I thought about that, just seemed strange to me that the install by default would not do that. Ill give it a go and see what happens. – maddog_94 Jun 17 '16 at 18:23
  • It's in the docs about setting it up. Not all that strange. Composer package can't install/add these lines automatically (nor would you want it too). – Mike Barwick Jun 17 '16 at 18:25
  • Remember to accept answer if it works for you. I see it's your first post - welcome! – Mike Barwick Jun 17 '16 at 18:25
  • I added it, it didn't work. i have looked all the place in doc for info on this. The only docs I find are for the $routeMiddleware settings. Nothing I can find has anything to do with $middlewareGroups. – maddog_94 Jun 17 '16 at 18:29
  • Dude...put it in the $routeMiddleware settings. You need to assign the middleware to a group or specific route manually. i.e. `Route::group(['middleware' => ['role:admin|owner']], function () { .. });` – Mike Barwick Jun 17 '16 at 18:33
  • Its already there! Please see original post. I have set up my route. My $routeMiddleware array has role, permission and ability from Entrust. Its not working. I cant find any other documentation to make this work. – maddog_94 Jun 17 '16 at 18:37
  • Make sure your also: `php artisan route:clear`...some stuff might be cached. – Mike Barwick Jun 17 '16 at 18:43
0

Well, the "right' way to do it was not discovered. So I used a work around. I used @role in the blade files. To me its a hack, but it works.

maddog_94
  • 21
  • 4