/** * Delete a category and all its links. * * @param Request $request type * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function delete(Request $request) { $category = new Category(); $link = new Link(); $category->user_id = $request->user_id; $category->category_id = $request->category_id; $category->where('id', $category->category_id)->where('user_id', $category->user_id)->delete(); $link->where('category_id', $category->category_id)->where('user_id', $category->user_id)->delete(); return redirect('/'); }
/** * Add a link to a category * * @param Request $request * * @return void */ public function store(Request $request, Category $category) { $this->validate($request, ['title' => 'required', 'link' => 'required', 'user_id' => 'required', 'category_id' => 'required']); $link = new Link(); $link->title = $request->title; $link->link = $request->link; $link->category_id = $request->category_id; $link->user_id = Auth::user()->id; $link->save(); return back(); }