您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ParsesEnum.php 320B

12345678910111213141516171819
  1. <?php
  2. namespace App\Enums\Concerns;
  3. trait ParsesEnum
  4. {
  5. public static function parse(string | self | null $value): ?static
  6. {
  7. if (! $value) {
  8. return null;
  9. }
  10. if ($value instanceof static) {
  11. return $value;
  12. }
  13. return static::tryFrom($value);
  14. }
  15. }