I created a function to store product data with image resizing for storage in the database, but when I run the function, I receive the notification that product information is inserted successfully but there is no data in the database
I created the function in my product controller to store the dat in the database and called the function in my web.php route for the product model. I expected the function to store data in the database but the data doesn’t get stored in the database but I do get a notification that data has been inserted.
Product insert controller
public function StoreProduct(Request $request){
if ($request ->file('image')) {
$manager = new ImageManager(new Driver());
$name_gen = hexdec(uniqid()).'.'.$request ->file('image')->getClientOriginalExtension();
$img = $manager->read($request ->file('image'));
$img = $img->resize(300,300);
$img->toJpeg(80)->save(base_path('public/upload/product/'.$name_gen));
$save_url = 'upload/product/'.$name_gen;
Product::insert([
'product_name' => $request->product_name,
'category_id' => $request->category_id,
'supplier_id' => $request->supplier_id,
'product_code' => $request->product_code,
'product_garage' => $request->product_garage,
'product_store' => $request->product_store,
'buying_date' => $request->buying_date,
'expire_date' => $request->expire_date,
'buying_price' => $request->buying_price,
'selling_price' => $request->selling_price,
'product_image' => $save_url,
'created_at' => Carbon::now(),
]);
} //end if
$notification = array(
'message' => 'Product Inserted Successfully',
'alert-type' => 'success'
);
return redirect()->route('all.product')->with($notification);
} // End Method
This is the route in my web.php
//Product Controller
Route::controller(ProductController::class)->group(function(){
Route::post('/store/product','StoreProduct')->name('product.store');
});
asap-glea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.