/** * Store a newly created resource in storage. * * @return Response */ public function store(Category $request) { $category = Categories::create($request->input()); // create the category flash()->success($request->input('name'), 'category has been created.'); //flash a success message to the user $directory = "/img/products/" . $category->id; Storage::makeDirectory($directory); // create a directory with the category id return Redirect::route('categories.create'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Requests\Category $request, $id) { try { DB::beginTransaction(); $category = Category::findOrFail($id); $category->fill($request->except('parent_id')); if ($request->has('parent_id')) { $category->parent_id = $request->input('parent_id'); } $category->update(); DB::commit(); flash()->success('Category information updated successfully.'); return redirect()->back(); } catch (\Exception $e) { DB::rollback(); flash()->error('Something went wrong. Please try again later.'); return redirect()->back()->withInput(); } }