HasAuthorization.php 735 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Dcat\Admin\Traits;
  3. use Dcat\Admin\Admin;
  4. use Illuminate\Contracts\Auth\Authenticatable;
  5. use Illuminate\Database\Eloquent\Model;
  6. trait HasAuthorization
  7. {
  8. /**
  9. * 验证权限.
  10. *
  11. * @return bool
  12. */
  13. public function passesAuthorization(): bool
  14. {
  15. return $this->authorize(Admin::user());
  16. }
  17. /**
  18. * 是否有权限判断.
  19. *
  20. * @param Model|Authenticatable|HasPermissions|null $user
  21. *
  22. * @return bool
  23. */
  24. protected function authorize($user): bool
  25. {
  26. return true;
  27. }
  28. /**
  29. * 返回无权限信息.
  30. *
  31. * @return mixed
  32. */
  33. public function failedAuthorization()
  34. {
  35. abort(403, __('admin.deny'));
  36. }
  37. }