Laravel 9: how to use enums in blade (<select>)?
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Laravel 9: How to Use Enums in Blade for Dynamic <select> Options
As developers working with modern PHP features, embracing strong typing through Enums is a significant step forward. They provide type safety and clarity that traditional string constants simply cannot match. However, bridging the gap between strongly-typed PHP objects (like Enums) and dynamic HTML rendering in Laravel Blade often presents unique challenges.
I recently encountered this exact scenario: how do you efficiently populate a <select> dropdown list using values derived from a PHP Enum? While there isn't a single, magical Blade directive for this yet, we can certainly create elegant solutions.
This post will walk you through the initial workaround, analyze why it works, and present a more scalable, idiomatic Laravel approach for handling this data flow.
The Initial Workaround: Static Methods and Helpers
When dealing with complex data structures in Blade, developers often resort to helper functions or static methods within the Enum class to expose the necessary data points. This is what I initially explored when trying to list the cases of an enum directly in a <select> tag.
The approach involves:
- Defining the enum with string values.
- Adding a static method (e.g.,
option()) to return an array mapping the Enum cases to their desired display options (['high' => 'high', ...]). - Creating a global helper function to call this static method and iterate over the result in the Blade file.
This method successfully solves the immediate problem of populating the <select> tag:
<select class="form-select" name="severity" required>
<option></option>
@foreach (case_severity() as $item)
<option value="{{ $item }}">{{ $item }}</option>
@endforeach
</select>
While functional, this approach introduces external dependency—a helper function that must be manually created and managed. If you have many forms requiring similar data mapping, managing numerous custom helpers can become cumbersome.
A More Scalable Laravel Approach: Data-Driven Views
As a senior developer, my preference leans towards solutions that leverage the power of the MVC architecture rather than relying heavily on ad-hoc helper functions for core data presentation. When dealing with dynamic lists in Laravel, the most robust pattern is to ensure your Controller or Model prepares the exact data needed for the view.
Instead of embedding the mapping logic inside the Enum, we should aim to pass a simple collection or array from the backend to the frontend. This keeps the business logic (the Enum) separate from the presentation logic (Blade).
Step 1: Prepare the Data in the Controller
In your controller, retrieve the necessary data and transform it into the exact format needed for the dropdown options. Since Laravel excels at Eloquent relationships and data manipulation, this is where we should focus our efforts, aligning with best practices discussed on platforms like Laravel Company.
If you are using an Enum to define status, you can map those enum values to human-readable display strings:
use App\Enums\CaseSeverity;
use Illuminate\Http\Request;
class FormController extends Controller
{
public function createForm(Request $request)
{
// Example data retrieval (simulated)
$severityOptions = CaseSeverity::options(); // Assuming you've made the method public and accessible
return view('forms.create', [
'available_severities' => $severityOptions,
]);
}
}
Step 2: Render in Blade
Now, the Blade file becomes much cleaner. We no longer need custom helper functions; we simply iterate over the data passed from the controller. This decouples the view from the internal structure of the Enum class, making it easier to maintain and test.
<select class="form-select" name="severity" required>
<option></option>
@foreach ($available_severities as $enumValue => $displayValue)
<option value="{{ $enumValue }}">{{ $displayValue }}</option>
@endforeach
</select>
Conclusion
The initial workaround using static methods is a perfectly valid, quick fix when you are constrained by the need to pull data directly from an Enum definition within a view. However, for larger, more maintainable Laravel applications, I strongly recommend shifting the responsibility of data structuring to the Controller or Model layer. By passing pre-formatted arrays and collections to your Blade views, you adhere better to SOLID principles, resulting in code that is more testable, easier to read, and scales much better as your application grows. Embrace the power of data flow over view-specific utility functions!