jeudi 12 mai 2016

Laravel getClientOriginalName inside foreach loop

I cannot call this method

getClientOriginalName 

inside this loop

        foreach ($request->file('images', []) as $scenesImagesData) {
            $scenes_images = new ScenesImages($scenesImagesData);
            $scenes_images->product()->associate($product);
            $fileName  = $scenesImagesData->getClientOriginalName();
            $filePath  = $targetPath . '\\' . $fileName;
            $scenes_images->save();
        }

I get following error:

Call to a member function getClientOriginalName() on a non-object

If I dd($scenesImagesData) I get this:

array:1 [▼
  "scenes_images" => UploadedFile {#30 ▼
    -test: false
    -originalName: "dog.jpg"
    -mimeType: "image/jpeg"
    -size: 434516
    -error: 0
  }
]

Which was the file I picked.

Thus I do have a

enctype="multipart/form-data"

in my form.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire