vendredi 28 juin 2019

"Array to string conversion" in Laravel 5 [duplicate]

This question already has an answer here:

I'm trying to upload multiple images in a single row called image in database, and access them to the view page. So far when I dd, I see the images array like this

"image" => array:2 [▼ 0 => UploadedFile {#289 ▶} 1 => UploadedFile {#291 ▶} ]

But I don't see them in database(it is showing null) and in the view it gives this error "Array to string conversion". How can I make them show in database also in the view.

I tried this from How to upload multiple image in laravel but am stuck.

Here are the codes

Controller

 public function store(Request $request) 
  { 

    $formInput=$request->all();
    $image=array();
    if($files=$request->file('image')){
        foreach($files as $file){
            $name=$file->getClientOriginalName();
            $file->move('images',$name);
            $image['image']=$name;
        }
    }
    //dd($formInput);

View.blade

   <div class="form-group" ">
               <label for="image">Image</label>
               <input type="file" name="image[]" multiple   class="form-control">
               <span class="text-danger"></span>
            </div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire