Пример #1
0
 /**
  * Save a new domain
  * @param Request $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required', 'url' => 'required|url']);
     $input = $request->all();
     $domain = $this->domainRepository->create($input);
     $category = '';
     // if a new category has been assigned
     if ($request->input('new_category')) {
         $category = $this->categoryRepository->create(['name' => $request->input('new_category')]);
     } elseif ($request->input('category_id')) {
         $category = $this->categoryRepository->find($request->input('category_id'));
     }
     if ($category) {
         $domain->category()->associate($category);
         $domain->save();
     }
     return redirect()->route('pdp.home')->with('success', 'Domain added');
 }
 /**
  * Delete existing category
  * @param $id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     $this->categoryRepository->destroy($id);
     return redirect()->route('pdp.categories')->with('success', 'Category deleted');
 }