/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Request $request) { $this->validate($request, ['name' => 'required', 'cashback' => 'required']); Category::find($id)->update($request->all()); Session::flash('status', 'The category has been updated successfully'); return redirect('admin/categories'); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { // $offer = Offer::find($id); $categories = Category::join('stores', 'stores.id', '=', 'categories.store_id')->select(['stores.name as store_name', 'categories.name', 'categories.id'])->orderBy('stores.name', 'asc')->orderBy('categories.name', 'asc')->get(); $stores = Store::ordered()->get(); $values = []; foreach ($stores as $store) { $cats = []; foreach ($categories as $category) { if (strcmp($category['store_name'], $store['name']) == 0) { $cats[] = array('id' => $category['id'], 'name' => $category['name']); } } $values[$store['name']] = $cats; } return view('admin.offers.edit')->with('categories', $values)->with('category_id', $offer->category_id)->with('store_name', Category::find($offer->category_id)->getStore()->name)->with('offer', $offer); }