Answer the question
In order to leave comments, you need to log in
SQLSTATE[01000]: Warning: 1265 Data truncated...?
Column migration:
$table->double('discount_price', 10, 2)->unsigned()->nullable();
<b>Discount Price</b>
<input type="number" name="discount_price" class="form-control" value="{{ $product->discount_price }}" placeholder="Discount price per item" min="1" max="999999" >
/**
* [addProduct - creates new Product Object]
* @param Request $request [recieves all data from inputs]
*/
public function addProduct(Request $request)
{
$galleryImgPath = [];
$this->validate($request, [
'product_name' => 'min:3|max:100|filled|required|string|unique:products,product_name',
'product_slug' => 'min:3|max:100|string|unique:products,product_slug',
'price' => 'min:1|max:999999|numeric|integer|filled',
'discount_price' => 'min:1|max:999999|numeric|integer',
'whole_sale_price' => 'min:1|max:999999|numeric|integer|',
'whole_sale_price_starts_from' => 'min:1|max:999999|numeric|integer',
'bar_code' => 'min:1|max:9999999|numeric|integer',
'stock' => 'max:9999|numeric|integer|',
'brand' => 'max:25|string',
'size' => 'max:55',
'description' => 'max:500|string|filled|required',
'avatar' => 'required',
'gallery' => 'required',
]);
if($request->hasFile('avatar') && $request->file('avatar')->isValid())
{
$extension = $request->file('avatar')->extension();
$avatarName = md5($request->file('avatar')->getClientOriginalName()).'.'.$extension;
$request->file('avatar')->move(public_path('imgs'), $avatarName);
$avatarPath = URL('/').'/imgs/'.$avatarName;
}
if($request->hasFile('gallery'))
{
foreach ($request->file('gallery') as $value) {
$extension = $value->extension();
$galleryImgName = md5($value->getClientOriginalName()).'.'.$extension;
$value->move(public_path('imgs'), $galleryImgName);
$galleryImgPath[] = URL('/').'/imgs/'.$galleryImgName;
}
$galleryImgPath_JSON = json_encode($galleryImgPath);
}
$productData = $request->all();
$generatedSlug = str_slug($request->product_name, '-');
if(empty($productData['product_slug']))
{
$productData['product_slug'] = $generatedSlug;
$product = Product::create($productData + ['avatar_url' => $avatarPath, 'pics_urls' => $galleryImgPath_JSON] );
}
else
{
$product = Product::create($productData + ['avatar_url' => $avatarPath, 'pics_urls' => $galleryImgPath_JSON] );
}
$product->save();
Session::put('addedProductConfirm', 'Product Added!');
return redirect()->action('[email protected]', '5');
}
Answer the question
In order to leave comments, you need to log in
Well, what does nullable have to do with it? 'Data truncated' how does it translate? Google it though and you will find the answer in the top ten.
Yes, almost all your questions are calmly searched by Google and solved in 10 minutes, instead you climb on the toaster every time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question