public function delcate($id) { try { $catenum = Category::where('id', '=', $id)->count(); if ($catenum == 0) { return redirect()->back()->withErrors('分类不存在!'); exit; } $onecate = Category::findOrFail($id); if ($onecate != null) { $onecate->delete(); $onecate::whereRaw("sortpath like '%," . $id . ",%' ")->delete(); } } catch (ModelNotFoundException $e) { return Redirect::to('/')->withInput()->withErrors('分类不存在!'); } return Redirect::to("/admin/cate?id=" . rand(0, 100)); }