title: Laravel 5.2 - Populate select options from database
body: <p>Trying to populate the dropdownlist from database. but there having some complication. Any help? This is based on laravel framework.</p>
  
  <p>Part of the code</p>
  
  <pre><code>$projects = DB::table('projects')-&gt;where('users_id','=',Auth()-&gt;User()-&gt;id)-&gt;get();
  
                          foreach($projects as $project){
                              echo '
                                      &lt;option value="&lt;?php $id = $project[id] ?&gt;" name="parentProj"&gt;'
                                          .$projectName = $project[id].
                                      '&lt;/option&gt;
                                    ';
                          }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>public function index(){
      $projects = DB::table('projects')-&gt;lists('id','projectName');
  
      return view('pages.todo', ['projects'=&gt; $projects);
  }
  </code></pre>