title: Proper way to populate dropdown from foreign key in Laravel 5.3
body: <p>can anyone help me in solving this problem? I've been stuck for days with the error <strong>htmlspecialchars() expects parameter 1 to be string, array given</strong> in Laravel 5.3.</p>
  
  <p>Here is my controller</p>
  
  <pre><code>public function create()
      {
        $categories = DB::table('categories')-&gt;pluck('name', 'id');
        foreach($categories as $category)
        {
            echo $category;
        }
        return view('admin.processor.create', compact('categories', $categories));
      }
  </code></pre>
  
  <p>And here's my view (the form)</p>
  
  <pre><code>{!! Form::open(['url' =&gt; '/processor']) !!}
      {!! csrf_field() !!}
      &lt;div class="form-group"&gt;
          {!! Form::label('make', 'Manufacturer') !!}
          {!! Form::select('make', ['Intel', 'AMD', 'Apple', 'Qualcomm', 'class' =&gt; 'form-control']) !!}
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          {!! Form::label('chipset', 'Chipset') !!}
          {!! Form::text('chipset', ['class' =&gt; 'form-control']) !!}
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          {!! Form::label('type', 'Type') !!}
          {!! Form::text('type', ['class' =&gt; 'form-control']) !!}
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          {!! Form::label('category', 'Category') !!}
          {!! Form::select('categories', $categories, null, ['class' =&gt; 'form-control']) !!}
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          {!! Form::submit('Add Processor', ['class' =&gt; 'btn btn-primary form-control']) !!}
      &lt;/div&gt;
  {!! Form::close() !!}
  </code></pre>
  
  <p>I just want to achieve something equivalent to this</p>
  
  <pre><code>&lt;select class="form-control" name="category"&gt;
      &lt;?php 
      $stmt = $connect-&gt;prepare("SELECT * FROM categories");
      $stmt-&gt;execute();
      while($row = $stmt-&gt;fetch())
      {
        print "&lt;option value='".$row['id']."'&gt;".$row['name']."&lt;/option&gt;";
      }
      ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>My Category Model</p>
  
  <pre><code>use Illuminate\Database\Eloquent\Model;
  
  class Category extends Model
  {
      protected $fillable = ['name'];
  
      public function processor()
      {
        return $this-&gt;hasMany('App\Processor', 'category_id');
      }
  }
  </code></pre>
  
  <p>My Processor Model</p>
  
  <pre><code>use Illuminate\Database\Eloquent\Model;
  
  class Processor extends Model
  {
      protected $fillable = ['make', 'chipset', 'type', 'category_id'];
  
      public function category()
      {
        return $this-&gt;belongsTo('App\Category', 'category_id');
      }
  }
  </code></pre>