dimanche 29 juillet 2018

Display image foreach

I'm trying to display image as loop from database.

I find this nice code from here https://appdividend.com/2018/02/05/laravel-multiple-images-upload-tutorial/ I could store mulitiple images.

Here is my store code

 public function store(Request $request)

    {

        $this->validate($request, [

                'filename' => 'required',
                'filename.*' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'

        ]);

        if($request->hasfile('filename'))
         {

            foreach($request->file('filename') as $image)
            {
                $name=$image->getClientOriginalName();
                $image->move(public_path().'/images/', $name);  
                $data[] = $name;  
            }
         }

         $form= new Form();
         $form->filename=json_encode($data);


        $form->save();

        return back()->with('success', 'Your images has been successfully');
    }

and I write like this but won't work.

@foreach ($data as $image)

     <div>   </div>

    <div>   </div>

 @endforeach

Could you teach me correct code?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire