$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
#Incorrect path of image in database and storage path
1 messages · Page 1 of 1 (latest)
Is this the same issue as https://discord.com/channels/297040613688475649/1165973582103453696 ? If so, why not continue there?
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
And you're doing something completely different as what we discussed then.. You're still just saving a random path, like I already said, the storage gives you the path that you should store. The docs have many examples on storing files;
https://laravel.com/docs/10.x/filesystem#file-uploads
https://laravel.com/docs/10.x/requests#files
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
I honestly have no clue what you're doing, Laravel has quite extensive docs on uploading files, but this is following nothing of that