#Incorrect path of image in database and storage path

1 messages · Page 1 of 1 (latest)

covert obsidian
#
$productValidated = $request->validated();


        $product = Product::find($id);

        if (!$product) {
            return response()->json([
                'error' => 'No product Found'
            ], 404);
        }

        if (Storage::disk('public')->exists($product->image)) {


            if ($request->hasFile("image")) {

                Storage::disk('public')->delete($product->image);

                $image = $request->file("image");

                $extension = $image->getClientOriginalExtension();

                $filename = time() . "." . $extension;

                $destinationPath = "Uploads/Product/" . $filename;

                Storage::disk('public')->put($destinationPath, file_get_contents($image));

                $product['image'] = $destinationPath;

            } else {

                $product['image'] = $product->image;

            }

        }



        $product['slug'] = Str::slug($productValidated['name']);

        $product['status'] = $productValidated['status'] ? 1 : 0;

        $product['popular'] = $productValidated['popular'] ? 1 : 0;

        $product['featured'] = $productValidated['featured'] ? 1 : 0;

        $product->update($productValidated);

        return response()->json([
            'success' => 'Product Created'
        ], 201);
``` i am trying to update my data from react to the laravel everything works well bu the issue is i am not able to store the correct path of image in database my image lgets stored in storage/Upload/Product/image name i need the path to be uploads/product/image
hollow isle
covert obsidian
#

no i have fixed that issue i am not able to store the the correct path of image in databse

#

database

#

/tmp/phpVfnuDy my path of image in databse is this

#

but what i am doing i am storing it in uploads/product/

#

when i create a new product it works fine but when i try to update it the path is incorrect

hollow isle
covert obsidian
#

the thing earlier i was having issue with new product now i am facing it with update but this time i am sure the path is incorrect in database to that what is having in storage

hollow isle
#

I honestly have no clue what you're doing, Laravel has quite extensive docs on uploading files, but this is following nothing of that