| 123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace App\Services;
- use App\Authority;
- use App\Owner;
- use App\User;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Gate;
- class UserService
- {
- /** @var CacheService $cacheService */
- private $cacheService;
- function __construct(){
- $this->cacheService = app('CacheService');
- }
- function hasRoles(User $user, $roles){
- $thisRoles=$this->cacheService->getOrExecute("user{$user['id']}->roles",function()use($user){
- return $user->roles;
- });
- return !!$roles->intersect($thisRoles)->count();
- }
- function getPermittingOwnerIds($user=null){
- if(!$user)return [];
- return $this->cacheService->getOrExecute("user{$user['id']}->getPermittingOwnerIds",function()use($user){
- return $user->getPermittingOwnerIdsAttribute() ?? [];
- });
- }
- }
|