RoleEnum.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Repositories\Enums;
  11. use Illuminate\Support\Str;
  12. use Jiannei\Enum\Laravel\Contracts\LocalizedEnumContract;
  13. use Jiannei\Enum\Laravel\FlaggedEnum;
  14. class RoleEnum extends FlaggedEnum implements LocalizedEnumContract
  15. {
  16. // const GUEST = 1 << 0;
  17. // const ADMIN = 1 << 1;
  18. // const SUPER_ADMIN = self::GUEST | self::ADMIN;
  19. const SUPER_ADMIN = 'admin';
  20. const SHOP_ADMIN = 'shop_admin';
  21. const COACH_VR = 'coach-vr';
  22. const COACH_CAR = 'coach-car';
  23. const BUSINESS = 'business';
  24. const BUSINESS_TEMP = 'business-temp';
  25. const CAIWU = 'caiwu';
  26. const YUNYING = 'yunying';
  27. public $name;
  28. public function __construct($flags)
  29. {
  30. parent::__construct($flags);
  31. $this->name = Str::ucfirst(Str::lower(Str::of($this->key)->replace('_', ' ')));
  32. }
  33. public static function makeRoles(): array
  34. {
  35. $rawRoles = self::getInstances();
  36. collect($rawRoles)->each(function ($item, $key) use (&$roles) {
  37. if ($item->value !== self::NONE) {
  38. $roles[] = ['name' => $item->name];
  39. }
  40. });
  41. return $roles;
  42. }
  43. }