/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = Validator::make(Input::all(), Products::$rules); if ($validator->passes()) { $product = new Products(); $product->name = addslashes(Input::get('name')); $product->color_id = Input::get('color'); $product->product_code = 0; $product->sp = Input::get('sp'); $product->cp = Input::get('cp'); $product->quantity = Input::get('quantity'); $product->type_id = Input::get('type_id'); $product->unit_id = Input::get('unit_id'); $product->save(); $product->setProductCode($product); $stock = new Stocks(); $stock->supplier_id = Input::get('supplier_id'); $stock->product_id = $product->id; $stock->quantity = Input::get('quantity'); $stock->save(); return Redirect::route('products.index')->with('success', 'Product created successfully'); } else { return Redirect::route('products.create')->withErrors($validator)->withInput(Input::all()); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = Validator::make(Input::all(), Stocks::$rules); if ($validator->passes()) { $stock = new Stocks(); $stock->supplier_id = Input::get('supplier_id'); $stock->product_id = Input::get('product_id'); $stock->quantity = Input::get('quantity'); $stock->save(); $product = Products::find(Input::get('product_id')); $product->quantity = $product->quantity + Input::get('quantity'); $product->save(); //Products::updateStock($stock->product_id); return Redirect::route('stocks.index')->with('success', 'Stock created successfully'); } else { return Redirect::route('stocks.create')->withErrors($validator)->withInput(Input::all()); } }