old value selected in dropdown laravel code example

Example 1: laravel old value for select option

@foreach($services as $service)
	@if (old('category') == $service->id)
  		<option value="{{ $service->id }}" selected>{{ $service->title }}</option>
  	@else
		<option value="{{ $service->id }}">{{ $service->title }}</option>
	@endif
@endforeach

Example 2: populate old value of dropdown laravel

# Populate Old value with default value selected
<select name="dial_code" id="dial_code">
@foreach($countries as $c)
    <option value="{{$c->phone_code}}" title="{{$c->name}}" {{old('dial_code', 966) == $c->phone_code ? 'selected' : ''}}>{{$c->iso2}} ({{$c->phone_code}})</option>
@endforeach
</select>

Tags:

Php Example