/** * @回车站彻底删除 */ public function realDelete($ids) { //检查删除安全和正确性 $arr = explode(',', $ids); //检查删除权限,防止当前用户删除其他用户文章漏洞 foreach ($arr as $v) { if (Article::find($v)->uid != Auth::id()) { return Redirect::route('articles.recycle')->with('error', '警告!无法对未授权的文章进行危险操作!'); } } //检查删除项必须是没有分类的文章,防止非法get提交 $record = Article::whereIn("id", $arr)->sum('cid'); if ($record > 0) { return Redirect::route('articles.recycle')->with('error', '警告!检查到有非回车站中的文章进行危险操作!'); } //彻底删除对应tag Tag::whereIn('aid', $arr)->delete(); //彻底删除文章 Article::destroy($arr); //回到回车站主页 return Redirect::route('articles.recycle')->with('message', '删除成功!'); }
/** * 删除分类,覆盖父类方法 * @param array|int $ids * @return int|void */ public static function destroy($ids) { if (empty($ids)) { return true; } //找出所有分类及其子分类id $list = self::all(); if (empty($list)) { return true; } $tree = App::make('ListTreeUtil', [$list]); //检测每个id是否合法并找出他们的所有后代id $resolveIds = array(); foreach ($ids as $id) { if (in_array($id, $resolveIds) or !$tree->has($id)) { continue; } $resolveIds[] = $id; $resolveIds = array_merge($resolveIds, $tree->getOffspringIds($id)); } if (empty($resolveIds)) { return true; } //删除文档,不调用destroy是因为它会先查找,再逐个delete Article::whereIn('cid', $resolveIds)->delete(); //删除分类 return self::whereIn('id', $resolveIds)->delete(); }
/** * @tag */ public function tag($uid, $tag) { //参数处理 $uid = intval($uid); $tag = strip_tags(trim($tag)); //获取当前标签下的文章列表 $rs = Tag::where('uid', $uid)->where('tag', $tag)->get(); if (count($rs) == 0) { return Response::make('tag not exist'); } $arr = array(); foreach ($rs as $v) { array_push($arr, $v->aid); } $articles = Article::whereIn('id', $arr)->where('status', 1)->paginate(5); //获取博客用户信息 $user = User::find($uid); //获取用户文章分类 $cates = $user->getCate; //获取用户所有tags $tags = Tag::where('uid', $uid)->groupBy('tag')->get(); //获取当前用户推荐文章5篇 $recoment = Article::where('uid', $uid)->where('status', 1)->orderBy('updated_at', 'desc')->take(5)->get(); return View::make('blog.tag', compact('articles'))->with('user', $user)->with('cates', $cates)->with('recoment', $recoment)->with('tags', $tags)->with('tag', $tag); }