How to use "enum" values in select option in Laravel?
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# How to Use `enum` Values in Select Options in Laravel: A Clean Approach
As a senior developer working with the Laravel ecosystem, we frequently encounter scenarios where database constraints, like `ENUM` types, need to be translated into user-friendly, interactive form elements. The issue you are facingâconditionally setting the `selected` attribute within a Blade template using complex `@if` statementsâis a common symptom of trying to manage presentation logic directly within the view layer rather than handling the data preparation in the controller or model.
This post will guide you through the most robust, clean, and scalable way to handle displaying and pre-selecting options based on your database `ENUM` values in Laravel Blade.
## The Problem with Conditional Selection in Blade
Your current approach using nested `@if` statements works, but it quickly becomes unwieldy, hard to maintain, and scales poorly if you have more than two or three choices.
```html
```
While this achieves the goal, it tightly couples your presentation logic to specific data points. A better approach is to separate *what* needs to be displayed (the options) from *how* they are selected (the initial state).
## The Recommended Solution: Iterating Over Data
The most idiomatic Laravel way to handle dynamic lists of options is by preparing an array or a Collection in your Controller and then iterating over it in the Blade file. This separates the data fetching logic from the presentation logic, adhering to the principle of separation of concerns.
### Step 1: Prepare the Data in the Controller
Instead of trying to deduce the selected value in the view, let the controller determine exactly which options should be displayed and which one should be marked as `selected`.
Assume you are fetching a record from your database that has an `contact_way` of 'email'. You can pass this data directly to the view.
```php
// Example Controller method (e.g., in a CustomerController)
public function showEditForm(Customer $customer)
{
// Fetch all available options from the enum, or just the current record's value
$availableWays = ['email', 'phone'];
$selectedValue = $customer->contact_way;
return view('customer.edit_form', compact('customer', 'availableWays', 'selectedValue'));
}
```
### Step 2: Implement the `foreach` Loop in Blade
Now, use a simple `foreach` loop to generate all the `