<?phpuseIlluminate\Support\Arr;useIlluminate\Support\Str;if(!function_exists('enum')){functionenum($key){// add a dot at the end of string to prevent undefined offset
$key.=Str::of($key)->contains(".")?"":".";// the first parameter of all enum keys are its filename
[$filename,$key]=explode(".",$key,2);// because we do not want to load the file every time use require
$enums=require__DIR__."/../Enums/$filename.php";// if the key that user provided not exists then null return
$enums=Arr::get($enums,$key,null);// if enum null means that key not found
throw_if($enums===null,'Exception',"Undefined enum '{$key}'");// if enum value is array its mean that user want to use it as collection
returnis_array($enums)?collect($enums):$enums;}}
<?php
useIlluminate\Support\Arr;
useIlluminate\Support\Str;
if(!function_exists('enum')){
functionenum($key)
{
// add a dot at the end of string to prevent undefined offset
$key.=Str::of($key)->contains(".")?"":".";
// the first parameter of all enum keys are its filename
[$filename,$key]=explode(".",$key,2);
// because we do not want to load the file every time use require
$enums=requireapp_path("Enums/$filename.php");
// if the key that user provided not exists then null return