jeudi 28 novembre 2019

How to upload multiple images with the same order of selection in Laravel?

How can i insert images to database in the same order I selected the images. Right now, a random image is selected as the first image and not the image I chose first.

Here is how I upload images to database(ProductController.php)

        $formInput=$request->except('filename');
        $product = product::create(array_merge($formInput, [
            'seller_id'=> Auth::user()->id,
            'user_id' => Auth::user()->id
        ]));
        foreach ($request->photos as $photo) {
           $filename = $photo->store('public/photos');
            ProductsPhoto::create([
                'product_id' => $product->id,
                'filename' => $filename
            ]);
        }
        return redirect()->back()->with('success', 'Product added successfully.');
    }

And this is how i retreive the first image

<img src="" alt="" width="80">



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire