Can we insert records and upload images into two tables using dropzone from one controller, if so, how? please give a suitable example.

  Sun 17 / 12 / 2023

  Posted by: Muhammad Siddique

Category : Laravel

Tags : laravel , php laravel

Description

Can we insert records and upload images  into two tables using dropzone from one controller, if so, how? Please give a suitable example.


View Code
                        Can we insert records and upload images  into two tables using dropzone from one controller, if so, how? Please give a suitable example.
                
  Answered by CDL

Yes, you can insert records into two tables and upload images using Dropzone from one controller in Laravel. Here's a basic example to guide you through the process. In this example, let's assume you have two tables: posts and images.


In js, set the images variable, get them, and pass them to the controller.


foreach ($request->file('images') as $image) {

   $imagePath = $image->store('images', 'public');


   Image::create([ 'path' => $imagePath]);

   Post::create([ 'path' => $imagePath]);


}


That's it :)

Solved
  Comment   Share
0 Likes   0 Comments