/** * * @param string $tag_id ID of tag to delete * @throws KnockCascadeDeleteAttemptException */ public function deleteTag($tag_id) { $tag = Tag::findOrFail($tag_id); if (!$tag == null) { if ($tag->roles->count() == 0) { $tag->delete(); } else { throw new KnockCascadeDeleteAttemptException("Sorry, you cannot delete Tag [" . $tag->name . "] because there are roles and actions associated with it. \n\t\t\t\t\t\tYou must first delete all associated roles and actions before it can be deleted."); } } }
/** * Remove the specified Tag from storage. * * @param int $tag_id * @return \Illuminate\Http\Response */ public function destroy($tag_id) { $tag = Tag::find($tag_id); try { if ($tag != null) { Knock::deleteTag($tag_id); return redirect('/knock/tags')->with('flash_message', 'Tag ' . $tag->name . ' has been deleted'); } } catch (KnockCascadeDeleteAttemptException $e) { return redirect('/knock/tags/' . $tag_id)->with('flash_message', $e->getMessage()); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request, $tag_id) { $tag = Tag::findOrFail($tag_id); $action = Knock::createRole($tag->name, Str::slug($request->get('name')), $tag->description, str_replace('"', "'", $request->input('description'))); return redirect('/knock/tags/' . $tag->id)->with('flash_message', 'Role ' . $action->role->name . ' created'); }