Level 6
$status = Status::from(2);
via https://stitcher.io/blog/php-enums#serializing-backed-enums
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello. I started with enums in PHP/Laravel and did something like that:
enum Status: int
{
case INITIATED = 0;
case SUCCESS = 1;
case DECLINED = 2;
}
public function slug(): string
{
return match($this) {
self::INITIATED => 'initiated',
self::SUCCESS => 'success',
self::DECLINED => 'declined'
}
In my database I store the id instead of something like 'success' as status to be later flexible. Is it possible to search in my code for the enum? I mean I have now the id for example 2... how can I get 'Status::SUCCESS' from this? Or is that a wrong way to do it?
$status = Status::from(2);
via https://stitcher.io/blog/php-enums#serializing-backed-enums
Please or to participate in this conversation.