I'm sorry to be a bother but I'm in this crap all day in a simple thing and I'm failing to see why. I'm trying to make a loop to insert in the database multiple data images. If you want to insert an image is working everything right but if I want to insert two or three it inserts only one. To insert two or three with the same table ID related I need to loop the problem I do a return $count to count the number of images and it returns me always 1. Ando here back to back and this will always give the same. I have something wrong?
Controller
$count = count($request->file('image'));
for ( $i=0; $i< $count; ++$i) {
$imagensportfolio = new ImagensPortfolio();
$file = array_get($imgportfolio,'image');
$destinationPath = 'image/portfolio/';
$extension = $request->file('image')->getClientOriginalExtension();
$fileName = rand(1111,9999) . '.' . $extension;
$imagensportfolio->image= $fileName[$i];
return $count;
Image::make($file)->resize(700, 400)->save($destinationPath.$fileName);
$portfolio->save();
$imagensportfolio->Portfolio()->associate($portfolio);
$imagensportfolio->save();
}
Index
<div class="col-md-3 col-lg-3">
{!! Form::label('imagens', 'Imagem', ['class' => 'label_perfil']) !!}
</div>
<div class="col-md-9 col-lg-9">
{!! Form::file('imagens[]', array('multiple'=>true),[
'class'=> 'input-file'
]) !!}
</div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire