Я новичок в Laravel и пытаюсь добавить продукты из панели администратора на индексную страницу, сначала она работала нормально, но теперь показывает ошибку SQLSTATE[HY000]: General error: 1364 Field 'care' doesn't have a default value
, есть ли решение этой проблемы?
SQLSTATE[HY000]: General error: 1364 Field 'care' doesn't have a
default value (SQL: insert into `products` (`product_name`,
`product_code`, `product_color`, `description`, `price`, `image`,
`updated_at`, `created_at`) values (Filter, ASD111, CLR, ASDF, 1000,
85525.png, 2019-01-10 17:18:33, 2019-01-10 17:18:33))
Это ProductsController:
public function addProduct(Request $request){
if($request->isMethod('post')){
$data = $request->all();
//echo "<pre>"; print_r($data); die;
$product = new Product;
$product->product_name = $data['product_name'];
$product->product_code = $data['product_code'];
$product->product_color = $data['product_color'];
if(!empty($data['description'])){
$product->description = $data['description'];
}else{
$product->description = '';
}
$product->price = $data['price'];
// Upload Image
if($request->hasFile('image')){
$image_tmp = Input::file('image');
if($image_tmp->isValid()){
$extension = $image_tmp->getClientOriginalExtension();
$filename = rand(111,99999).'.'.$extension;
$large_image_path =
'images/backend_images/products/large/'.$filename;
$medium_image_path =
'images/backend_images/products/medium/'.$filename;
$small_image_path =
'images/backend_images/products/small/'.$filename;
// Resize Images
Image::make($image_tmp)->save($large_image_path);
Image::make($image_tmp)->resize(600,600)->save($medium_image_path);
Image::make($image_tmp)->resize(300,300)->save($small_image_path);
// Store image name in products table
$product->image = $filename;
}
}
$product->save();
return redirect('/admin/view-products')-
>with('flash_message_success','Product has been added successfully!');
}
return view('admin.products.add_product');
}
public function editProduct(Request $request, $id=null){
if($request->isMethod('post')){
$data = $request->all();
//echo "<pre>"; print_r($data); die;
if($request->hasFile('image')){
$image_tmp = Input::file('image');
if($image_tmp->isValid()){
$extension = $image_tmp->getClientOriginalExtension();
$filename = rand(111,99999).'.'.$extension;
$large_image_path = 'images/backend_images/products/large/'.$filename;
$medium_image_path = 'images/backend_images/products/medium/'.$filename;
$small_image_path = 'images/backend_images/products/small/'.$filename;
// Resize Images
Image::make($image_tmp)->save($large_image_path);
Image::make($image_tmp)->resize(600,600)->save($medium_image_path);
Image::make($image_tmp)->resize(300,300)->save($small_image_path);
// Store image name in products table
$product->image = $filename;
}
}
if(empty($data['description'])){
$data['description'] = '';
}
Product::where(['id'=>$id])->update(['product_name'=>$data['product_name'],'product_code'=>$data['product_code'],'product_color'=>$data['product_color'],'description'=>$data['description'],'price'=>$data['price'],'image'=>$fileName]);
return redirect()->back()->with('flash_message_success','Product updated successfully!');
}
//Get product details
$productDetails = Product::where(['id'=>$id])->first();
return view('admin.products.edit_product')->with(compact('productDetails'));
}