2
I have a form that already creates one record at a time in the bank. I would like to inform in this same form through a quantity field ($request->Quant) where I can enter the amount to be created or duplicated from that same record with different id.
Follow the code of my Controller:
public function criarRegistro(Request $request)
{
$this->validate($request,[
'category_id' => 'required',
'card_details' => 'required',
'card_image' => 'mimes:jpg,jpeg,png,svg',
'impuls' => 'required',
]);
if($request->hasFile('card_image')){
$image = $request->file('card_image');
$imageName = time().'.jpg';
$location = 'assets/images/cardimage/'.$imageName;
Image::make($image)->save($location);
$name = $imageName;
}else{
$name = '';
$impuls = '';
}
$cat = cardsubcategory::find($request->category_id );
// AQUI ONDE ESTOU TENTANDO FAZER A MULTIPLICAÇÃO DO MESMO REGISTRO
$numero = $request->quant * $cat;
card::create([
'sub_category_id' => $request->category_id,
'card_details' => $request->card_details,
'card_image' => $name,
'category_id' => $cat->id,
'status' => 1,
'tipo' => 1,
'impuls' => $request->impuls,
]);
return back()->with('success', 'Criado com Sucesso');
}
You want to duplicate the cardsubcategory?
– JrD