jeudi 13 juillet 2017

laravel upload files in many inputs

I'm trying to upload files in 4 inputs files i get the solution from here but the problem the last file4 input file uploaded in all fields in database

in my blade form

{!! Form::file('file1', null,['class'=>'form-control']) !!}
{!! Form::file('file2', null,['class'=>'form-control']) !!}
{!! Form::file('file3', null,['class'=>'form-control']) !!}
{!! Form::file('file4', null,['class'=>'form-control']) !!}

in my controller

$input = $request->all();
    $files =[];
    if ($request->file('file1')) $files[] = $request->file('file1');
    if ($request->file('file2')) $files[] = $request->file('file2');
    if ($request->file('file3')) $files[] = $request->file('file3');
    if ($request->file('file4')) $files[] = $request->file('file4');
    foreach ($files as $file)
    {
        if(!empty($file)){
            $destinationPath = public_path() . '/uploads';
            $filename = $file->getClientOriginalName();
            $file->move($destinationPath, $filename);
        }

    }
    $model = new Project($input);
    $model -> file1 = $filename;
    $model -> file2 = $filename;
    $model -> file3 = $filename;
    $model -> file4 = $filename;
    $model->save();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire