I have a form that allows for the upload of multiple images alongside other inputs and that works fine. However, I cannot update the entries with multiple images as I get the error:
Array to string conversion
Here is the part of the form which handles the upload:
<div class="form-group {{$errors->has('photo') ? 'has-error' : ''}}">
{!! Form::label('photo', 'Image 1:') !!}
{!! Form::file('photo', null, ['class'=>'form-control'])!!}
@if($errors->has('photo'))
{{$errors->first('photo')}}
@endif
</div>
<div class="form-group {{$errors->has('image') ? 'has-error' : ''}}">
{!! Form::label('image', 'Image 2:') !!}
{!! Form::file('image[]', null, ['class'=>'form-control'])!!}
@if($errors->has('image'))
{{$errors->first('image')}}
@endif
</div>
<div class="form-group {{$errors->has('image') ? 'has-error' : ''}}">
{!! Form::label('image', 'Image 3:') !!}
{!! Form::file('image[]', null, ['class'=>'form-control'])!!}
@if($errors->has('image'))
{{$errors->first('image')}}
@endif
</div>
<div class="form-group {{$errors->has('image') ? 'has-error' : ''}}">
{!! Form::label('image', 'Image 4:') !!}
{!! Form::file('image[]', null, ['class'=>'form-control'])!!}
@if($errors->has('image'))
{{$errors->first('image')}}
@endif
</div>
and the method:
public function update(GamesRequest $request, $id)
{
$gameSearch = Game::findOrFail($id);
$photoSearch = Photo::findOrFail($id);
$input = $request->all();
if($file = $request->file('photo')){
$name = $file->getClientOriginalName();
$file->move('images/games/', $name);
$input['photo'] = '/images/games/' . $name;
}
$input['title'] = $request->title;
$input['price'] = $request->price;
$input['score'] = $request->score;
$input['description'] = $request->description;
$input['category_id'] = $request->category_id;
$input['promote'] = 0;
$input['sold'] = $request->sold;
$input['manual'] = $request->manual;
$input['box'] = $request->box;
$input['realphoto'] = $request->realphoto;
$input['youtube'] = $request->youtube;
$gameSearch->update($input);
// Handle multiple file upload
if($images = $request->file('image'))
{
foreach($images as $key => $image) {
$name = $image->getClientOriginalName();
if ($image->move('images/games/', $name)) {
// store image to database.
$input = $request->all();
$input->game_id = $input->id;
$input->image = '/images/games/' . $name;
$photoSearch->update($input);
}
}
}
return redirect('admin/games');
}
When I upload just one photo that doesn't use the image array, it works fine