0

I am trying to keep input from multi select dropdown, using old(). Anyway to get the selected values highlighted

<select name="contract_id[]" class="form-control selectpicker" multiple>
    @foreach($contracts as $contract)
        @if( ( isset($usercontract) && $usercontract->where('id' , $contract->id) != "[]" ) ||
                                            ( count($errors) && old('contract_id[]') == $contract->id ) )
           <option value="{{ $contract->id }}" selected="">{{ $contract->name }}</option>   
        @else 
          <option value="{{ $contract->id }}">{{ $contract->name }}</option>
        @endif

    @endforeach
</select> 
1
  • Google: laravel multiselect old Commented Nov 19, 2015 at 11:59

1 Answer 1

1

Found the solution used in_array() function in php.

<select name="contract_id[]" class="form-control selectpicker" multiple>
      @foreach($contracts as $contract)
          @if( ( isset($usercontract) && $usercontract->where('id' , $contract->id) != "[]" ) ||
                       ( count($errors) && in_array($contract->id, old('contract_id')) == $contract->id ) )
              <option value="{{ $contract->id }}" selected="">{{ $contract->name }}</option>   
          @else 
              <option value="{{ $contract->id }}">{{ $contract->name }}</option>
          @endif

       @endforeach
</select> 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.