namespace App\Concerns\Enums;
trait HasLabel
{
public function label(): string
{
return str($this->name)
// convert to title case
->title()
// replace underscores with spaces
->headline();
}
}
namespace App\Enums;
use App\Concerns\Enums\HasLabel;
enum Status: int
{
use HasLabel;
case PENDING = 0;
case FAILED = 1;
case REFUNDED = 2;
case PARTIALLY_REFUNDED = 3;
case PARTIALLY_PAID = 4;
case PAID = 5;
case PARTIALLY_PAID_AND_REFUNDED = 6;
case PARTIALLY_PAID_AND_PARTIALLY_REFUNDED = 7;
}
// some examples
use App\Enums\Status;
Status::PENDING->label();
// Pending
Status::FAILED->label();
// Failed
Status::REFUNDED->label();
// Refunded
Status::PARTIALLY_REFUNDED->label();
// Partially Refunded
Status::PARTIALLY_PAID->label();
// Partially Paid
Status::PAID->label();
// Paid
Status::PARTIALLY_PAID_AND_REFUNDED->label();
// Partially Paid And Refunded
Status::PARTIALLY_PAID_AND_PARTIALLY_REFUNDED->label();
// Partially Paid And Partially Refunded