Repository: spatie/laravel-permission (php)

Issue:
Undefined index: guard_name
**Describe the bug**
This afternoon I upgraded the version of this package we're using to [5.5.10](https://github.com/spatie/laravel-permission/releases/tag/5.5.10) and then started seeing an error to do with guard_name being undefined:

```
ErrorException
Undefined index: guard_name

Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
vendor/spatie/laravel-permission/src/Models/Role.php:73
```

That line consists of 
```
getModelForGuard($this->attributes['guard_name']),
```

I've downgraded back to 5.5.9 for now which no longer causes the error. It would be good if someone could take a look into this though!

**Versions**
- spatie/laravel-permission package version: **5.5.10**
- illuminate/framework package version: **8.83.25**
- PHP version: **7.4**
- Database version: **MySQL 5.7**


**To Reproduce**
Here is my example code and/or tests showing the problem in my app:
```
Role::with('users')->get();
```
causes the error, however
```
Role::with('permissions')->get();
````
works fine

**Expected behavior**
I'd expect roles to be returned with users that have the role


Pull request description:
Fix undefined index guard_name
Closes #2218
Bug introduced on #2098
With Tests

Patch:
diff --git a/src/Models/Permission.php b/src/Models/Permission.php
index 9ef30ed..066a378 100644
--- a/src/Models/Permission.php
+++ b/src/Models/Permission.php
@@ -64,7 +64,7 @@ class Permission extends Model implements PermissionContract
     public function users(): BelongsToMany
     {
         return $this->morphedByMany(
-            getModelForGuard($this->attributes['guard_name']),
+            getModelForGuard($this->attributes['guard_name'] ?? config('auth.defaults.guard')),
             'model',
             config('permission.table_names.model_has_permissions'),
             PermissionRegistrar::$pivotPermission,
diff --git a/src/Models/Role.php b/src/Models/Role.php
index 731e999..84f9136 100644
--- a/src/Models/Role.php
+++ b/src/Models/Role.php
@@ -70,7 +70,7 @@ class Role extends Model implements RoleContract
     public function users(): BelongsToMany
     {
         return $this->morphedByMany(
-            getModelForGuard($this->attributes['guard_name']),
+            getModelForGuard($this->attributes['guard_name'] ?? config('auth.defaults.guard')),
             'model',
             config('permission.table_names.model_has_roles'),
             PermissionRegistrar::$pivotRole,


Test patch:
diff --git a/tests/PermissionTest.php b/tests/PermissionTest.php
index 35f02d0..b157d24 100644
--- a/tests/PermissionTest.php
+++ b/tests/PermissionTest.php
@@ -7,6 +7,20 @@ use Spatie\Permission\Exceptions\PermissionAlreadyExists;
 
 class PermissionTest extends TestCase
 {
+    /** @test */
+    public function it_get_user_models_using_with()
+    {
+        $this->testUser->givePermissionTo($this->testUserPermission);
+
+        $permission = app(Permission::class)::with('users')
+            ->where($this->testUserPermission->getKeyName(), $this->testUserPermission->getKey())
+            ->first();
+
+        $this->assertEquals($permission->getKey(), $this->testUserPermission->getKey());
+        $this->assertCount(1, $permission->users);
+        $this->assertEquals($permission->users[0]->id, $this->testUser->id);
+    }
+
     /** @test */
     public function it_throws_an_exception_when_the_permission_already_exists()
     {
diff --git a/tests/RoleTest.php b/tests/RoleTest.php
index 61a958b..35e287d 100644
--- a/tests/RoleTest.php
+++ b/tests/RoleTest.php
@@ -21,6 +21,19 @@ class RoleTest extends TestCase
         Permission::create(['name' => 'wrong-guard-permission', 'guard_name' => 'admin']);
     }
 
+    /** @test */
+    public function it_get_user_models_using_with()
+    {
+        $this->testUser->assignRole($this->testUserRole);
+
+        $role = app(Role::class)::with('users')
+            ->where($this->testUserRole->getKeyName(), $this->testUserRole->getKey())->first();
+
+        $this->assertEquals($role->getKey(), $this->testUserRole->getKey());
+        $this->assertCount(1, $role->users);
+        $this->assertEquals($role->users[0]->id, $this->testUser->id);
+    }
+
     /** @test */
     public function it_has_user_models_of_the_right_class()
     {