I am using Laravel 4.2 and I have this form to upload multiple images
the problem when I submit the form it returns to the view page and the first image only uploaded.
can anyone please review my code and correct my mistake
{{ Form::open(array('url'=>'doAddProjectImage', 'files'=>'true', 'method'=>'PUT', 'class'=>'margin-top-30 width-100per pull-left')) }}
{{ Form::file('img[]', array('class'=>'file', 'multiple'=>true)) }}
{{ Form::submit('Add images to project', array('class'=>'btn-success btn pull-left')) }}
{{ Form::hidden('pid', Session::get('insId')) }}
{{ Form::close() }}
and this is my controller
public function doAddProjectImage()
{
$proId = Input::get('pid');
$projectImages = new ProjectsImages();
$files = Input::file('img');
foreach($files as $file) {
$destination_path = 'images/projects/';
$filename = str_random(6) . '_' . $file->getClientOriginalName();
$file->move($destination_path, $filename);
$projectImages->image = $filename;
$projectImages->image_id = $proId;
$projectImages->save();
}
return Redirect::to('admin/view-project');
}