
PHP 8.1 Enums: Backed Enums and Laravel Eloquent Casts
PHP 8.1 Enums: Backed Enums and Laravel Eloquent Casts PHP enums landed in version 8.1, and they've quietly become one of the most adopted features across the ecosystem. With 85.9% of Packagist users now running PHP 8.x ( Stitcher.io , June 2025), there's little excuse to keep scattering magic strings and integer constants across your codebase. Enums give you type safety, autocompletion, and a single source of truth for fixed sets of values. This tutorial walks through backed enums from scratch, then shows how Laravel's Eloquent casting system turns database columns into enum instances automatically. You'll get copy-pasteable code for every step. Even if PHP 8.1 reached end-of-life on December 31, 2025, the enum syntax carries forward unchanged into 8.2, 8.3, and 8.4 -- so everything here applies regardless of your PHP version. PHP version upgrade guide TL;DR: PHP 8.1 enums replace scattered class constants with type-safe, autocompletable value objects. Backed enums map cases to string
Continue reading on Dev.to
Opens in a new tab

