title: Laravel set option to selected if option id is in an array list in blade view
body: <p>I made query in my controller and send it to my blade :</p>
  
  <pre><code>public function editContractorAssociation(DeveloperContractorAssociation $developer_contractor_association, Request $request)
      {
          $id = $request-&gt;id;
          $developer_contractor_association = DeveloperContractorAssociation::whereHas('defect_types', function ($query) use($id) {
              $query-&gt;where('developer_contractor_associations.id', $id);
          })-&gt;orwhereHas('contractor', function ($query) use($id) {
              $query-&gt;where('developer_contractor_associations.id', $id);
          })-&gt;first();
          return view('dev-admin.contractors.associations.edit', ['developer_contractor_association' =&gt; $developer_contractor_association]);
      }
  </code></pre>
  
  <p>and when I call <code>{{ $developer_contractor_association-&gt;defect_types }}</code> in my blade, I get this : </p>
  
  <pre><code>[
      {
          "id":2,
          "title":"Wiring",
          "details":"Fix wiring",
          "created_by":"22",
          "created_at":"2019-09-04 11:39:48",
          "updated_at":"2019-09-04 11:39:48",
          "deleted_at":null,
          "is_custom":1,
          "developer_id":1,
          "pivot":{"dca_id":87,"defect_type_id":2}},
          {"id":3,"title":"Plumbing",
              "details": "Fix Pipe",
              "created_by":"22",
              "created_at":"2019-09-04 11:40:07",
              "updated_at":"2019-09-04 11:40:07",
              "deleted_at":null,
              "is_custom":1,
              "developer_id":1,
          "pivot":{"dca_id":87,"defect_type_id":3}
      }
  ]
  </code></pre>
  
  <p>Now I have a select field that list all the defect type that existed :</p>
  
  <pre><code>&lt;select class="selectpicker {{ $errors-&gt;has('defect-type-id') ? 'is-invalid' : '' }}" name="defect-type-id[]" id="defect-type-id" multiple data-style="selectpicker-style" data-width="100%" title="Defect Types"&gt;
      @foreach(App\DefectType::select('id','title')-&gt;get() as $defect_type)
          &lt;option value="{{$defect_type-&gt;id}}"&gt;{{$defect_type-&gt;title}}&lt;/option&gt;
      @endforeach
  &lt;/select&gt;
  </code></pre>
  
  <p>When population the option for the select field, How can I check if the <code>id</code> is in the <code>defect_type_id</code> JSON and set the option to selected. Something like this :</p>
  
  <pre><code>&lt;select class="selectpicker {{ $errors-&gt;has('defect-type-id') ? 'is-invalid' : '' }}" name="defect-type-id[]" id="defect-type-id" multiple data-style="selectpicker-style" data-width="100%" title="Defect Types"&gt;
      @foreach(App\DefectType::select('id','title')-&gt;get() as $defect_type)
          {{if $defect_type-&gt;id in $defect_type_list}}
              &lt;option value="{{$defect_type-&gt;id}}"&gt;{{$defect_type-&gt;title}} selected&lt;/option&gt;
          {{else}}
          &lt;option value="{{$defect_type-&gt;id}}"&gt;{{$defect_type-&gt;title}}&lt;/option&gt;
      @endforeach
  &lt;/select&gt;
  </code></pre>