@edmond_brakus
To use "enum" values in a select option in Laravel, follow these steps:
1 2 3 4 5 6 |
class User extends Model { use HasFactory; public $enumStatus = ['active', 'inactive']; } |
1 2 3 4 5 6 7 8 9 10 11 12 |
// In your controller $user = User::find($id); $enumStatus = User::$enumStatus; return view('edit', compact('user', 'enumStatus')); // In your view <select name="status"> @foreach($enumStatus as $status) <option value="{{ $status }}" {{ $user->status == $status ? 'selected' : '' }}>{{ $status }}</option> @endforeach </select> |
1 2 3 |
// In your controller $user->status = $request->status; $user->save(); |
By following these steps, you can use enum values in select options in Laravel and make it easier to manage and update your data.