Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

array_merge(): Argument #1 is not an array @ using UserHasAnyRole middleware #120

Closed
SiIverHawk opened this issue Sep 3, 2019 · 2 comments
Labels

Comments

@SiIverHawk
Copy link

I'm trying to use UserHasAnyRole on my middleware's controller like this

public function __construct() { $this->middleware('auth'); $this->middleware('has.anyroles:admin,medic'); }

then I went to the middleware and then, in the beginning of the handle function I dd($roles) and this is what it cointains:
array:2 [▼ 0 => "admin" 1 => "medic" ]

on line 37 at $roles = call_user_func_array('array_merge', $roles); is where the exception jumps on array_merge(): Argument #1 is not an array

@Fancisco027
Copy link

I have the same problem, did you solve it?

@SiIverHawk
Copy link
Author

Yes, I had to make a middleware on app>http>middlewares called UserHasAnyRole then I copied and pasted the same code from vendor>caffeinated>src>Middleware>UserHasAnyRole and deleted this line:
$roles = call_user_func_array('array_merge', $roles);

then in your Kernel.php you must assign your new created middleware:
on $routeMiddleware:

'has.anyRoles' => \App\Http\Middleware\UserHasAnyRole::class,

after that you should be allowed to use 'has.anyroles:admin,roleX,roleY,etc' in your controller's middleware

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants