Laravel 5.2 - Gate Auth issue: Illegal offset type in isset or empty
<p>Running: Laravel 5.2
    Issue:   Gate
    Error:   Illegal offset type in isset or empty</p>

<p>Here is my <code>AuthServiceProvider</code> in my Boot Method</p>

<pre><code>    foreach ($this-&gt;getPermissions() as $permission) {
        $gate-&gt;define($permission-&gt;code, function (User $user) use ($permission) {
            if ($user-&gt;isAdmin())
                return true;
            return $user-&gt;hasPermission($permission);
        });
    }
</code></pre>

<p>My Permissions and Roles are seeded into the DB...</p>

<p>On my <code>User</code> Class, are the following methods (used above)</p>

<pre><code>/**
 * Determine if the user has the given role.
 *
 * @param  mixed $role
 * @return boolean
 */
public function hasRole($role)
{
    if (is_string($role))
        return $this-&gt;roles-&gt;contains('code', $role);

    if ($role instanceof Role)
        return $this-&gt;roles()-&gt;where('id', $role-&gt;id)-&gt;count();

    if ($role instanceof Collection)
    {
        foreach ($role as $r)
            if ( ! $this-&gt;hasRole($r) )
                return false;
        return true;
    }
}

/**
 * Determine if the user may perform the given permission.
 *
 * @param  Permission $permission
 * @return boolean
 */
public function hasPermission(Permission $permission)
{
    return $this-&gt;hasRole($permission-&gt;roles);
}
</code></pre>

<p>Now, when I view my site, nothing is wrong.
When I run a test, to ensure that normal users have 0 permissions, I get the error..</p>

<p>My Test class:</p>

<pre><code>/** @test */
public function a_user_with_no_role_can_do_nothing()
{
    $user = factory(User::class)-&gt;create();
    $permissions = Permission::all();

    foreach ($permissions as $perm)
        $this-&gt;assertFalse($user-&gt;can($perm));    // line 43
}
</code></pre>

<p>That creates the following error:</p>

<pre><code>There was 1 error:

1) UsersTest::a_user_with_no_role_can_do_nothing
ErrorException: Illegal offset type in isset or empty

C:\xampp\htdocs\dev\itcdash\vendor\laravel\framework\src\Illuminate\Auth\Access\Gate.php:321
C:\xampp\htdocs\dev\itcdash\vendor\laravel\framework\src\Illuminate\Auth\Access\Gate.php:265
C:\xampp\htdocs\dev\itcdash\vendor\laravel\framework\src\Illuminate\Auth\Access\Gate.php:243
C:\xampp\htdocs\dev\itcdash\vendor\laravel\framework\src\Illuminate\Auth\Access\Gate.php:199
C:\xampp\htdocs\dev\itcdash\vendor\laravel\framework\src\Illuminate\Foundation\Auth\Access\Authorizable.php:18
C:\xampp\htdocs\dev\itcdash\tests\acl\UsersTest.php:43
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:129

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
</code></pre>

<p>Why am I getting this error??</p>

<p>Thank you!</p>