/** * Create a new task. * * @param Request $request * @return Response */ public function store(Request $request) { $this->authorize('blog', Auth::user()); $this->validate($request, Post::storeRules()); $this->validate($request, Category::storeRules()); $this->validate($request, Tag::storeRules()); \DB::transaction(function () use($request) { $post = Post::create(Post::storeAttributes($request)); $categories = explode(',', $request->categories); // remove empty items from array $categories = array_filter($categories); // trim all the items in array $categories = array_map('trim', $categories); $post->saveCategories($categories); $tags = explode(',', $request->tags); // remove empty items from array $tags = array_filter($tags); // trim all the items in array $tags = array_map('trim', $tags); $post->saveTags($tags); }); return redirect(route('blog')); }
/** * Destroy the given task. * * @param Request $request * @param Task $task * @return Response */ public function destroy(Request $request, Post $post) { $this->authorize('admin', Auth::user()); $post->delete(); return redirect(route('blog')); }