public function addRequestProduct(ProductsRequest $request){
$validated = $request->validated();
$objProduct = new Products();
$objProduct = $objProduct->create($validated, [
'is_reccomended' => $request->has('is_reccomended') ? 1 : 0,
'image' => ImageDNK::save($request, 'image'),
'tab_bg' => ImageDNK::save($request, 'tab_bg'),
]);
if(!$objProduct){
return back()->with('error', 'Товар не создан. Попробуйте ещё раз');
}
$hasCategory = $request->input('product_category') != 0;
if($hasCategory){
$objCatsRels = new CategoriesRelationship();
$objCatsRels = $objCatsRels->create([
'object_id' => $objProduct->id,
'category_id' => $request->input('product_category'),
]);
}
if($objProduct && (!$hasCategory || $objCatsRels)){
return redirect(route('admin.products.edit', ['id' => $objProduct->id]))->with('success', trans('messages.products.successCreated'));
}
return back();
}
public function addRequestProduct(ProductsRequest $request){
$validated = $request->validated();
$objProduct = new Products();
$validated['is_reccomended'] = $request->has('is_reccomended') ? 1 : 0;
$validated['image'] = ImageDNK::save($request, 'image');
$validated['tab_bg'] = ImageDNK::save($request, 'tab_bg');
$objProduct = $objProduct->create($validated);
if(!$objProduct){
return back()->with('error', 'Товар не создан. Попробуйте ещё раз');
}
$hasCategory = $request->input('product_category') != 0;
if($hasCategory){
$objCatsRels = new CategoriesRelationship();
$objCatsRels = $objCatsRels->create([
'object_id' => $objProduct->id,
'category_id' => $request->input('product_category'),
]);
}
if($objProduct && (!$hasCategory || $objCatsRels)){
return redirect(route('admin.products.edit', ['id' => $objProduct->id]))->with('success', trans('messages.products.successCreated'));
}
return back();
}
$objProduct = $objProduct->create($validated, [
'is_reccomended' => $request->has('is_reccomended') ? true : false,
'image' => ImageDNK::save($request, 'image'),
'tab_bg' => ImageDNK::save($request, 'tab_bg'),
]);
$validatedFields = $request->validate($rules);
$model->fill($validatedFields);
$validator = Validator::make($request->all(), [
'title' => 'required|string|min:4|max:25',
'slug' => array(
'required',
'string',
'min:4',
'max:25',
'unique:products',
'regex:/^[a-z0-9а-яё-]+$/u',
),
'excerpt' => 'required|string|min:4|max:100',
'content' => 'required|string|min:4|max:300',
'descrtitle' => 'required|string|min:4|max:100',
'descrtext' => 'required|string|min:4|max:300',
'descr' => 'required|string|min:4|max:300',
'regular_price' => array(
'required',
'regex:/\d+/',
),
'discount' => array(
'required',
'min:0',
'max:100',
'regex:/^\d+(\.\d{1,2})?$/',
),
'image' => 'mimes:jpeg,jpg,png,gif|max:10000',
'tab_bg' => 'mimes:jpeg,jpg,png,gif|max:10000',
]);
$model->fill($validator);
Решение есть но для этого надо вносить изменения в vendor а это не есть хорошо.Похожая проблема
Поэтому ищу другой вариант.