i have productions/create , i need that when i save type_id = 1 save cut = 1 ,when type_id = 2 save grinding = 1 , type_id = 3 save polishing = 1, when type_id = 4 save hem = 1 (these four), I tried this
DB::transaction(function () use ($prices, $request, $product) {
Product::where('id', '=', (string) $product->id)->update(['status' =>0]);
if (Product::where($request->input('type_id'),'=',1)){
Product::create([
'worker_id' => $request['worker_id'],
'price_id' => $request['price_id'],
'cut' => 1,
'type_id' => $request['type_id'],
'storage_id' => $request['storage_id'],
'length' => $product->length,
'width' => $product->width,
'area'=> $product->length * $product->width,
]);
} elseif (Product::where($request->input('type_id'),'=', 2)){
Product::create([
'worker_id' => $request['worker_id'],
'price_id' => $request['price_id'],
'type_id' => $request['type_id'],
'grinding' => 1,
'storage_id' => $request['storage_id'],
'length' => $product->length,
'width' => $product->width,
'area'=> $product->length * $product->width,
]);
} elseif (Product::where($request->input('type_id'),'=',3)){
Product::create([
'worker_id' => $request['worker_id'],
'price_id' => $request['price_id'],
'type_id' => $request['type_id'],
'polishing' => 1,
'storage_id' => $request['storage_id'],
'length' => $product->length,
'width' => $product->width,
'area'=> $product->length * $product->width,
]);
} elseif (Product::where($request->input('type_id'),'=',4)) {
Product::create([
'worker_id' => $request['worker_id'],
'price_id' => $request['price_id'],
'type_id' => $request['type_id'],
'hem' => 1,
'storage_id' => $request['storage_id'],
'length' => $product->length,
'width' => $product->width,
'area' => $product->length * $product->width,
]);
}
});
but it didn't work out,
how can i do this