title: How to save multiple pictures into table by a given item id?
body: <p>I am new to Laravel. This is a similar situation as <a href="http://laravel.com/docs/4.2/eloquent#inserting-related-models" rel="nofollow noreferrer">Laravel one to many</a></p>
  
  <p>I have about less than 10 pictures to insert a pictures table, where the picture has a foreign key as "item_id". And I want to insert several picture name into "picture_name" where "item_id" is 2 or 7 (any item).</p>
  
  <p>But I got a error as below. Any help? Thanks!
  <img src="https://i.stack.imgur.com/5stDh.png" alt="Error"></p>
  
  <p>My controller code:</p>
  
  <pre><code>$uploadPicture = array();
  
      foreach( $pictures as $picture )
      {
  
          $destinationPath = public_path().'/assets/img';
          $fileName = $picture-&gt;getClientOriginalName();
          $uploadSuccess = $picture-&gt;move($destinationPath, $fileName);
  
  
          $pictureModel = new Picture;
          array_push($uploadPicture, new Picture(array('picture_name' =&gt; $fileName)));
      }
  
      $item = Item::find($item-&gt;id);
  
      $item-&gt;pictures()-&gt;saveMany($uploadPicture);
  
  
      if($item-&gt;save() &amp;&amp; $item-&gt;pictures()-&gt;saveMany($uploadPicture))
      {
          echo "&lt;pre&gt;".var_dump(Input::file('pictures'))."&lt;/pre&gt;";
      }
  </code></pre>
  
  <p>My model code:
      
  
  <pre><code>class Item extends Eloquent {
  protected $fillable = [];
  
  
  /**
   * [pictures description]
   * @return [type] [description]
   */
  public function pictures()
  {
      return $this-&gt;hasMany('Pictures');
  
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>&lt;?php
  
  
  class Picture extends Eloquent {
  protected $fillable = [];
  
  public function items()
  {
      return $this-&gt;belongsTo('Item');
  }
  
  }
  </code></pre>
  
  <p><strong>Solution:</strong>
  Add the code    protected $fillable = ['picture_name'];
  to the picture model. </p>