/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $product = new Product(); $product->name = $request->input('name'); $product->price = $request->input('price'); $product->description = $request->input('description'); $product->save(); for ($i = 0; $i < $request->input('stock'); $i++) { $item = new ProductItem(); $item->code = date('YmdHis') . '.' . $i; $item = $product->item()->save($item); } }