Steve
Steve

Reputation: 1672

Avoiding duplicate values while editing:

When a user tries to edit their region, I've showed their previous region with selected but their previous region is also on dropdown box. How can we show that region has only one?

In code below, $user->region->region_name and one of the $reg->region_name are same.

 <select  name="region" id="region" class="form-control" required>
         <option value="{{ $user->region_id}}" selected>{{$user->region->region_name}}</option>
           @foreach($region as $reg)
             <option value="{{$reg->id}}">{{$reg->region_name}}</option>
           @endforeach                
  </select><br>

Upvotes: 1

Views: 49

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

Use simple conditional to skip selected region:

@foreach ($region as $reg)
    @if ($user->region_id !== $reg->id)
        <option value="{{ $reg->id }}">{{ $reg->region_name }}</option>
    @endif
@endforeach     

Upvotes: 3

Related Questions