Question: I want to insert data where the images are. my problem is when I want to insert multiple images it gives me an error `Array to string conversion` , and when I do `dd ($ data)` it gives me an array:

```
6 [▼
   0 => "1598359099.jpeg"
   1 => "1598359099.jpeg"
   2 => "1598359099.jpeg"
   3 => "1598359099.jpeg"
   4 => "1598359099.jpeg"
   5 => "1598359099.jpeg"
]

```

**AnnonceController.php**

```
public function store(Request $request)
    {
       $Annonce = new Annonce($request->all());
       $jdate = Carbon::now();
       //insert image
       if($request->hasFile('image'))
       {
        $image = $request->file('image');
        $image->storeAs("public\annonces\\".$jdate->format('F').$jdate->year,$image->getClientOriginalName());
        $Annonce->image = "annonces\\".$jdate->format('F').$jdate->year."\\".$image->getClientOriginalName(); 
        }
        //insert multi images
         if($request->hasfile('images'))
         {
            foreach($request->file('images') as $file)
            {
                $name = time().'.'.$file->extension();
                $file->move(public_path().'/files/', $name);  
                $data[] = $name;
            }
         }
        $file->images=json_encode($data);
        dd($data);
        $Annonce->save();
        return Redirect::to("/")
        ->withSuccess('Great! file has been successfully uploaded.');
    }

```

**create\_annonces\_table.php**

```
$table->text('images');

```

Answer: 
```
if($request->hasfile('images')){
     $data = array(); // add variable data in array empty
     foreach($request->file('images') as $file){
       $name = time().'.'.$file->extension();
       $file->move(public_path().'/files/', $name);  
       array_push($data,$name);
       }
   }

```
Use this

```
array_push($data,$name);

```

Instead of

```
$data[] = $name;

```