title: Auto Select option form Laravel
body: <p>i want to make my edit is auto select option but when i try is doesnt work. i need my form edit is auto select the data if i click data with id_cms_companies "1" from my table location is auto select and show in the first select option.
  and its show the name of table cms_companies
  here my code :</p>
  
  
  
  
  
  <pre><code>&lt;select class='form-control' name='id_cms_companies'&gt;
                          &lt;option&gt;- Companies -&lt;/option&gt;
                          &lt;?php 
                          $category = DB::table("cms_companies")-&gt;get();
                          foreach($category as $cat) 
                          {
                           if($cat-&gt;name == $row-&gt;id_cms_companies)
                           {
                            echo "&lt;option value='$cat-&gt;name' selected&gt;$cat-&gt;name&lt;/option&gt;";
                           }
                           else
                           {
                            echo "&lt;option value='$cat-&gt;name'&gt;$cat-&gt;name&lt;/option&gt;";
                           }
                          }
                           ?&gt;
                          &lt;/select&gt;
  </code></pre>
  
  
  
  <p>and here my controller :</p>
  
  
  
  
  
  <pre><code>public function getEdit($id)  {
          $data['row'] = locations::find($id);
          return view('locations_form',$data);
      }
  
      public function postEditSave($id) {
          $simpan= array();
          $simpan['name']=Request::input('name');
          $simpan['id_cms_companies']=Request::input('id_cms_companies');
  
          DB::table('locations')-&gt;where('id', $id)-&gt;update($simpan);
          Session::flash('edit', 'Data berhasil di Edit');
          return Redirect::to('locations');
      }
  </code></pre>
  
  
  
  <p>here my table :</p>
  
  <p><a href="http://i.stack.imgur.com/WBs7U.png" rel="nofollow">table locations</a></p>
  
  <p>and here for my </p>
  
  <p><a href="http://i.stack.imgur.com/Y4Gsi.png" rel="nofollow">table cms_companies</a></p>