role); } /** * Determine whether the user can create models. * * @param \App\Models\User $authUser * @return boolean */ public function create(User $authUser): bool { return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } /** * Determine whether the user can update the model. * * @param \App\Models\User $authUser * @param \App\Models\User $user * @return boolean */ public function update(User $authUser, User $user): bool { return $authUser->getRouteKey() === $user->getRouteKey() or (UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and UserStaticRules::atLeastRole($authUser, $user->role)); } /** * Determine whether the user can delete the model. * * @param \App\Models\User $authUser * @param \App\Models\User $user * @return boolean */ public function delete(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and UserStaticRules::atLeastRole($authUser, $user->role); } /** * Determine whether the user can restore the model. * * @param \App\Models\User $authUser * @param \App\Models\User $user * @return boolean */ public function restore(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and UserStaticRules::atLeastRole($authUser, $user->role); } /** * Determine whether the user can permanently delete the model. * * @param \App\Models\User $authUser * @param \App\Models\User $user * @return booleanean */ public function forceDelete(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and UserStaticRules::atLeastRole($authUser, $user->role); } /** * Determine whether the user can duplicate the model. * * @param \App\Models\User $authUser * @param \App\Models\User $user * @return booleanean */ public function duplicate(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and UserStaticRules::atLeastRole($authUser, $user->role); } /** * Determine whether the user can publish/unpublish the model. * * @param \App\Models\User $authUser * @param \App\Models\User $user * @return booleanean */ public function changePublished(User $authUser, User $user): bool { return $authUser->getRouteKey() !== $user->getRouteKey() and UserStaticRules::atLeastRole($authUser, RoleEnum::admin) and UserStaticRules::atLeastRole($authUser, $user->role); } }