array value auto fill in old value laravel 8

<select id="recommended_food"   multiple="multiple" size=3 style='height: 100%;' name="recommended_food[]">
    @if ($food->recomemded_food)
      {{ ($val = 'Fries')
        && $chosen = in_array($val, $food->recommended_food)
        ? 'selected':null}}
      <option value="{{$val}}" {{$chosen}}>{{$val}}</option>
      {{ ($val = 'Hot Dogs')
        && $chosen = in_array($val, $food->recommended_food)
        ? 'selected':null}}
      <option value="{{$val}}" {{$chosen}}>{{$val}}</option>
      {{ ($val = 'Hamburgers')
        && $chosen = in_array($val, $food->recommended_food)
        ? 'selected':null}}
      <option value="{{$val}}" {{$chosen}}>{{$val}}</option>
    @endif
  </select>

3.9
10
A-312 69370 points

                                    {{ (collect(old('forWhom'))-&gt;contains($key)) ? 'selected':'' }} 

{{ (in_array($key,$info-&gt;forWhom)) ? 'selected' : ''}}

3.9 (10 Votes)
0
0
0
A-312 69370 points

                                    &lt;select id=&quot;forWhom&quot; name=&quot;forWhom[]&quot; multiple class=&quot;form-control chosen&quot;&gt;
        &lt;option value=&quot;&quot;&gt;--- Select ---&lt;/option&gt;
        @foreach ($desgInfo as $key =&gt; $value)
            &lt;option value=&quot;{{ $key }}&quot; 
               {{ (collect(old('forWhom'))-&gt;contains($key)) ? 'selected':'' }} 
               {{ (in_array($key,$info-&gt;forWhom)) ? 'selected' : ''}}  
               /&gt;
               {{ $value }}
            &lt;/option&gt;
        @endforeach
    &lt;/select&gt;

0
0
3.4
5
Krish 100200 points

                                    #1.
&lt;div class=&quot;form-group&quot;&gt;
  &lt;label for=&quot;roles&quot; class=&quot;form-control-label&quot;&gt;Roles&lt;/label&gt;
  &lt;select name=&quot;roles[]&quot; id=&quot;roles&quot; data-placeholder=&quot;Choose role...&quot; multiple class=&quot;standardSelect&quot;&gt;
    &lt;option value=&quot;&quot; label=&quot;default&quot;&gt;&lt;/option&gt;
    @foreach($roles as $role)
      &lt;option value=&quot;{{ $role }}&quot; {!! (collect(old('roles'))-&gt;contains($role)) ? 'selected=&quot;selected&quot;' : '' !!}&gt;{{ $role }}&lt;/option&gt;
    @endforeach
  &lt;/select&gt;
 &lt;/div&gt;
#2.  
@if(count($categories) &gt; 0)
  @foreach($categories as $category)
      &lt;option value=&quot;{{ $category-&gt;id }}&quot; {{ (old('lawyer_fields') == null ? '' : in_array($category-&gt;id ,old('lawyer_fields')) ? &quot;selected&quot;:&quot;&quot;) }}&gt;
                                            {{ $category-&gt;name }}
      &lt;/option&gt;
  @endforeach
  @else
       &lt;option disabled&gt;بدون انتخاب&lt;/option&gt;
@endif
#3.
&lt;label for=&quot;name&quot;&gt;Tags&lt;/label&gt;
    &lt;select name=&quot;tags[]&quot; class=&quot;form-control select-tag&quot; multiple&gt;
      @foreach($tags as $tag)
        &lt;option value=&quot;{{$tag-&gt;id}}&quot; {{in_array($tag-&gt;id, old(&quot;tags&quot;) ?: []) ? &quot;selected&quot;: &quot;&quot;}}&gt;{{$tag-&gt;name}}&lt;/option&gt;
      @endforeach
 &lt;/select&gt;

3.4 (5 Votes)
0
4
7
Krish 100200 points

                                    &lt;select id=&quot;forWhom&quot; name=&quot;forWhom[]&quot; multiple class=&quot;form-control chosen&quot;&gt;
    &lt;option value=&quot;&quot;&gt;--- Select ---&lt;/option&gt;
    @foreach ($desgInfo as $key =&gt; $value)
        &lt;option value=&quot;{{ $key }}&quot; 
           {{ (collect(old('forWhom'))-&gt;contains($key)) ? 'selected':'' }}  /&gt;
           {{ $value }}
        &lt;/option&gt;
    @endforeach
&lt;/select&gt;

4 (7 Votes)
0
4
2
Phoenix Logan 186125 points

                                    &lt;label for=&quot;name&quot;&gt;Tags&lt;/label&gt;
    &lt;select name=&quot;tags[]&quot; class=&quot;form-control select-tag&quot; multiple&gt;
      @foreach($tags as $tag)
        &lt;option value=&quot;{{$tag-&gt;id}}&quot; {{in_array($tag-&gt;id, old(&quot;tags&quot;) ?: []) ? &quot;selected&quot;: &quot;&quot;}}&gt;{{$tag-&gt;name}}&lt;/option&gt;
      @endforeach
    &lt;/select&gt;

4 (2 Votes)
0
3.5
2
Awgiedawgie 440220 points

                                    &lt;select name=&quot;options[]&quot; id=&quot;options&quot; class=&quot;form-control&quot; multiple&gt;
    @foreach($settings-&gt;includes-&gt;get('optionList') as $option)
        &lt;option value=&quot;{{ $option-&gt;id }}&quot; {{ (collect(old('options'))-&gt;contains($option-&gt;id)) ? 'selected':'' }}&gt;{{ $option-&gt;name }}&lt;/option&gt;
    @endforeach
&lt;/select&gt;

3.5 (2 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source