Intento subir varias imágenes a la vez y lo que es subirla al servidor la sube pero solo guarda el nombre de la primera en la base de datos las otras la redimensiona y las guarda en la carpeta pero no inserta el nombre en la base de datos a que se puede deber ??
Formulario
{!! Form::open(array('route'=>'posts.store','method'=>'POST', 'files'=>true)) !!}
{{ Form::hidden('user_id', auth()->user()->id) }}
{{ Form::hidden('di', 'di') }}
{{ Form::label('image', 'Imagen') }}
{!! Form::file('profile_image[]', array('multiple' => true)) !!}
{{ Form::submit('Guardar', ['class' => 'btn btn-sm btn-primary']) }}
{!! Form::close() !!}
Controller
public function store(Request $request)
{
$post = Post::create($request->all());
$files = $request->file('profile_image');
foreach ((array) $files as $file)
{
if($file) {
//get filename with extension
$filenamewithextension = $file->getClientOriginalName();
//get filename without extension
$filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);
//get file extension
$extension = $file->getClientOriginalExtension();
//filename to store
$filenametostore = $filename.'_'.time().'.'.$extension;
$post->fill(['file' => $filenametostore])->save();
//Upload File
$file->storeAs('public/images', $filenametostore);
$file->storeAs('public/images/mini', $filenametostore);
$file->storeAs('public/images/minin', $filenametostore);
//Resize image
$thumbnailpath = public_path('storage/images/mini/'.$filenametostore);
$img = Image::make($thumbnailpath)->resize(null, 200, function($constraint) {
$constraint->aspectRatio();
});
$img->save($thumbnailpath);
//Resize image perfil
$thumbnailpat = public_path('storage/images/minin/'.$filenametostore);
$imgn = Image::make($thumbnailpat)->resize(null, 200, function($constraint) {
$constraint->aspectRatio();
})->resizeCanvas(200, 200 );
$imgn->save($thumbnailpat);}
}
return back()->with('info', 'Foto añadida correctamente');
}