bristol-su /
control
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | namespace BristolSU\ControlDB\Observers\Pivots; |
||
| 4 | |||
| 5 | use BristolSU\ControlDB\Cache\Pivots\UserRole as UserRoleCache; |
||
| 6 | use BristolSU\ControlDB\Contracts\Models\Role; |
||
| 7 | use BristolSU\ControlDB\Contracts\Models\User; |
||
| 8 | use Illuminate\Contracts\Cache\Repository; |
||
| 9 | |||
| 10 | class UserRoleObserverClearCache |
||
|
0 ignored issues
–
show
|
|||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
|
0 ignored issues
–
show
|
|||
| 14 | * @var Repository |
||
| 15 | */ |
||
| 16 | private $cache; |
||
|
0 ignored issues
–
show
|
|||
| 17 | |||
| 18 | 12 | public function __construct(Repository $cache) |
|
|
0 ignored issues
–
show
|
|||
| 19 | { |
||
| 20 | 12 | $this->cache = $cache; |
|
| 21 | 12 | } |
|
| 22 | |||
| 23 | 12 | public function addUserToRole(User $user, Role $role) |
|
|
0 ignored issues
–
show
|
|||
| 24 | { |
||
| 25 | 12 | $this->cache->forget(UserRoleCache::class . '@getRolesThroughUser:' . $user->id()); |
|
| 26 | 12 | $this->cache->forget(UserRoleCache::class . '@getUsersThroughRole:' . $role->id()); |
|
| 27 | 12 | } |
|
| 28 | |||
| 29 | 4 | public function removeUserFromRole(User $user, Role $role): void |
|
|
0 ignored issues
–
show
|
|||
| 30 | { |
||
| 31 | 4 | $this->cache->forget(UserRoleCache::class . '@getRolesThroughUser:' . $user->id()); |
|
| 32 | 4 | $this->cache->forget(UserRoleCache::class . '@getUsersThroughRole:' . $role->id()); |
|
| 33 | 4 | } |
|
| 34 | |||
| 35 | } |