all(), [ 'title' => 'required|string|unique:bootcamp_categories,title', ]); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $data['title'] = $request->title; $data['slug'] = slugify($request->title); BootcampCategory::insert($data); Session::flash('success', get_phrase('Category has been created.')); return redirect()->back(); } public function delete($id) { $category = BootcampCategory::where('id', $id); if ($category->doesntExist()) { Session::flash('error', get_phrase('Data not found.')); return redirect()->back(); } $category->delete(); Session::flash('success', get_phrase('Category has been deleted.')); return redirect()->back(); } public function update(Request $request, $id) { $category = BootcampCategory::where('id', $id); if ($category->doesntExist()) { Session::flash('error', get_phrase('Data not found.')); return redirect()->back(); } $validator = Validator::make($request->all(), [ 'title' => 'required|string|unique:bootcamp_categories,title,' . $id, ]); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $data['title'] = $request->title; $data['slug'] = slugify($request->title); $category->update($data); Session::flash('success', get_phrase('Category has been updated.')); return redirect()->back(); } }