/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Request $request) { //$this->validate($request, ['name' => 'required']); // Uncomment and modify if needed. $category = Categories::findOrFail($id); $category->update($request->all()); return redirect('categories'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Request $request, $id) { $category = Categories::findOrFail($id); $category->name = $request->name; $category->save(); return Redirect::route('categories.create'); }
/** * Update the specified resource in storage. * * @param $id * @param Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function update($id, Request $request) { $this->validate($request, ['name' => 'required']); $category = Categories::findOrFail($id); $category->update($request->all()); \Session::flash('success', 'Category updated'); return redirect('/categories'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Request $request) { $category = Categories::findOrFail($id); $this->validate($request, ['name' => 'required|max:100']); $category->update($request->all()); Flash::success('Category updated'); return redirect()->action('CategoriesController@index'); }
/** * Show the form for creating a new resource. * * @return Response */ public function create(Request $request) { $category = Categories::findOrFail($request->cat_id); $products = Categories::products($request->cat_id); return view('products.create')->with('category', $category)->with('products', $products); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $category = Categories::findOrFail($id); if ($category->delete()) { \Flash::success('Category deleted'); } else { \Flash::error('Error'); } return 'done'; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function delete($id) { $category = Categories::findOrFail($id); $product_category = DB::table('products')->join('categories', 'products.category_id', '=', 'categories.id')->select('products.*', 'categories.name as categoryName')->where('categories.id', '=', $id)->count(); if ($product_category = 0) { $category->delete(); return Redirect::to('admin/categories'); } else { return Redirect::to('admin/categories')->withErrors('The category have products so can not delete this category'); } }
public function getCategoryPost($id = null) { $category = Categories::findOrFail($id); $page_title = $category->name; $posts = $category->posts()->where('active', 1)->orderBy('updated_at', 'desc')->paginate($this->per_page); $data = compact('posts', 'page_title'); return view('posts.page', $data); }