title: How to load items in a multi select dropdown for update - Laravel
body: <p>Using Laravel, I have created an updatable form. One of these fields is a multi-select dropdown. This field should display all locations linked to a given project. So the user can see which location he selected and if he wants to update. But on this moment, there is noting selected. Bellow you will find the code.   </p>
  
  <h3>ProjectsController.php</h3>
  
  <p>The controller send the data to the blade template like this:</p>
  
  <pre><code>public function edit(Project $project)
      {
         $locations = Location::where('project_id', $project-&gt;id)-&gt;get();
         return view('projects.edit', [
           'project'           =&gt; $project,
           'location'          =&gt; $locations,
           'edit'              =&gt; true
         ]);
  </code></pre>
  
  <h3>edit.blade.php</h3>
  
  <pre><code>&lt;select multiple class="form-control" name="locations[]"&gt;
      &lt;option {{old('location',$project-&gt;location) == "Room A1" ? 'selected' : ''}}  value="Room A1"&gt;Room A1&lt;/option&gt;
      &lt;option {{old('location',$project-&gt;location) == "Room C1" ? 'selected' : ''}}  value="Room C1"&gt;Room C1&lt;/option&gt;
      &lt;option {{old('location',$project-&gt;location) == "Room D2" ? 'selected' : ''}}  value="Room D2"&gt;Room D2&lt;/option&gt;
      &lt;option {{old('location',$project-&gt;location) == "Room A3" ? 'selected' : ''}}  value="Room A3"&gt;Room A3&lt;/option&gt;
      &lt;option {{old('location',$project-&gt;location) == "Room G3" ? 'selected' : ''}}  value="Room G3"&gt;Room G3&lt;/option&gt;
  &lt;/select&gt;
  
  </code></pre>
  
  <p>This field should normally display all the values selected. However, this isn't the case. 
  For example: For project with id 1, Room A1 and Room D2 should be selected in dropdown.</p>
  
  <p>The code is working for the single dropdown but not for the multi-select dropdown. I don't quite understand why.
  Could you help me on the way? Thanks.</p>
  
  <p>The data that should be displayed in this multi-select dropdown is stored in the database. Presented in this table:</p>
  
  <h3>Locations Table</h3>
  
  <pre><code>+----+------------+----------+--+
  | id | project_id | location |  |
  +----+------------+----------+--+
  |  1 |          1 | Room A1  |  |
  |  2 |          1 | Room D2  |  |
  |  3 |          2 | Room A1  |  |
  +----+------------+----------+--+
  </code></pre>