|-------------------------------------------------------------------------- | | This route group applies the "web" middleware group to every route | it contains. The "web" middleware group is defined in your HTTP | kernel and includes session state, CSRF protection, and more. | */ Route::group(['middleware' => ['web']], function () { // Route::get('/login', function () { return view('login');}); // List all boxes Route::get('/boxes', function () { $boxes = Box::orderBy('created_at', 'asc')->get(); return view('box', ['boxes' => $boxes]); }); // Add new box Route::post('/boxes', function (Request $request) { $validator = Validator::make($request->all(), ['name' => 'required|max:255']); if ($validator->fails()) { return redirect('/boxes')->withInput()->withErrors($validator); } $box = new Box(); $box->name = $request->name; $box->save(); return redirect('/boxes'); }); // Delete a box Route::delete('/box/{box}', function (Box $box) { $box->delete(); return redirect('/boxes'); }); });
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update() { $input = Input::all(); $product = Product::find($input['id']); $rules = array('name' => 'required', 'product_category' => 'required', 'supplier' => 'required'); $validator = Validator::make($input, $rules); if ($validator->passes()) { $product->name = $input['name']; $product->product_category_id = $input['product_category']; $product->supplier_id = $input['supplier']; $product->save(); foreach ($input['box'] as $i => $v) { $box = Box::find($v); $box->size = $input['size'][$i]; $box->no_of_packs = $input['packs'][$i]; $box->purchase_price = $input['purchase_price'][$i]; $box->selling_price_1 = $input['selling_price_1'][$i]; $box->selling_price_2 = $input['selling_price_2'][$i]; $box->save(); } if (isset($input['asize'])) { foreach ($input['asize'] as $i => $v) { $box = new Box(); $box->product_id = $input['id']; $box->size = $v; $box->no_of_packs = $input['apacks'][$i]; $box->purchase_price = $input['apurchase_price'][$i]; $box->selling_price_1 = $input['aselling_price_1'][$i]; $box->selling_price_2 = $input['aselling_price_2'][$i]; $box->save(); } } if (isset($input['trash'])) { Box::destroy($input['trash']); } return Redirect::action('ProductController@index'); } return Redirect::action('ProductController@show', $input['id']); }