title: why do I get preg_replace() error when submitting a post form in Laravel?
body: <p>I have built a simple application laravel 4. I have scaffolding setup for adding posts which seems to be working fine. I have setup Stapler and image uploading package. When I setup to use single image uploads its pretty good and it works a charm. I recently looked at the docs <a href="https://github.com/CodeSleeve/stapler#examples" rel="nofollow">here</a></p>
  
  <p>It states that you can do multiple uploads so I went about doing it as explained in the docs. Here are my coded pages:</p>
  
  <p>Post.php model:</p>
  
  <pre><code>&lt;?php
  
  class Post extends Eloquent {
      use Codesleeve\Stapler\Stapler;
      protected $guarded = array();
  
      // A user has many profile pictures.
      public function galleryImages(){
          return $this-&gt;hasMany('GalleryImage');
      }
  
      public static $rules = array(
          'title' =&gt; 'required',
          'body' =&gt; 'required'
      );
  
      public function __construct(array $attributes = array()) {
      $this-&gt;hasAttachedFile('picture', [
          'styles' =&gt; [
              'thumbnail' =&gt; '100x100',
              'large' =&gt; '300x300'
          ],
          // 'url' =&gt; '/system/:attachment/:id_partition/:style/:filename',
          'default_url' =&gt; '/:attachment/:style/missing.jpg'
      ]);
  
      parent::__construct($attributes);
      }
  
  }
  </code></pre>
  
  <p>PostsController.php</p>
  
  <pre><code>/**
       * Store a newly created resource in storage.
       *
       * @return Response
       */
      public function store()
      {
          $input = Input::all();
          $validation = Validator::make($input, Post::$rules);
  
          if ($validation-&gt;passes())
          {
              $this-&gt;post-&gt;create($input);
  
              return Redirect::route('posts.index');
          }
          $post = Post::create(['picture' =&gt; Input::file('picture')]);
  
          foreach(Input::file('photos') as $photo)
          {
              $galleryImage = new GalleryImage();             
              $galleryImage-&gt;photo = $photo;                   
              $user-&gt;galleryImages()-&gt;save($galleryImage);    
          }
  
  
          return Redirect::route('posts.create')
              -&gt;withInput()
              -&gt;withErrors($validation)
              -&gt;with('message', 'There were validation errors.');
      }
  </code></pre>
  
  <p>This has save functions and other functions inside it too.</p>
  
  <p>GalleryImage.php gallery image model to use in the post controller</p>
  
  <pre><code>&lt;?php
  
  class GalleryImage extends Eloquent {
      protected $guarded = array();
  
      public static $rules = array();
  
      public function __construct(array $attributes = array()) {
  
      $this-&gt;hasAttachedFile('photo', [
          'styles' =&gt; [
              'thumbnail' =&gt; '300x300#'
          ]
      ]);
  
      parent::__construct($attributes);
      }
  
      // A gallery image belongs to a post.
      public function post(){
          return $this-&gt;belongsTo('Post');
      }
  
  }
  </code></pre>
  
  <p>My create.blade.php template to post the post itself</p>
  
  <pre><code>@extends('layouts.scaffold')
  
  @section('main')
  
  &lt;h1&gt;Create Post&lt;/h1&gt;
  
  {{ Form::open(array('route' =&gt; 'posts.store', 'files' =&gt; true)) }}
      &lt;ul&gt;
          &lt;li&gt;
              {{ Form::label('title', 'Title:') }}
              {{ Form::text('title') }}
          &lt;/li&gt;
  
          &lt;li&gt;
              {{ Form::label('body', 'Body:') }}
              {{ Form::textarea('body') }}
          &lt;/li&gt;
  
          &lt;li&gt;
              {{ Form::file('picture') }}
          &lt;/li&gt;
          &lt;li&gt;
              {{ Form::file( 'photo[]', ['multiple' =&gt; true] ) }}
          &lt;/li&gt;
  
          &lt;li&gt;
              {{ Form::submit('Submit', array('class' =&gt; 'btn btn-info')) }}
  
      &lt;/ul&gt;
  {{ Form::close() }}
  
  @if ($errors-&gt;any())
      &lt;ul&gt;
          {{ implode('', $errors-&gt;all('&lt;li class="error"&gt;:message&lt;/li&gt;')) }}
      &lt;/ul&gt;
  @endif
  
  @stop
  </code></pre>
  
  <p>When I post the form with a single images attached its fine and saves to the db and it works a treat but when I save it with multiple image uploads I get this error:</p>
  
  <pre><code>ErrorException
  preg_replace(): Parameter mismatch, pattern is a string while replacement is an array
  </code></pre>
  
  <p>The full stack trace is <a href="https://gist.github.com/mdunbavan/8731592" rel="nofollow">here</a> in my gist of the files</p>
  
  <p>Can anyone point out to me why this error happens. From my research its creating a multidimensional array that needs flattening I think but I am unsure if this is true.</p>
  
  <p>I have been banging my head against a brick wall with this for ages.</p>