public function edit($id) { $data["_title"] = array("top" => "編輯分類", "main" => "Home", "sub" => "cate"); $data["active"] = "cates"; $data["post"] = Cate::find($id); return View::make('admin.categories.edit', $data); }
/** * @分类文章列表 */ public function cate($cid) { try { $cid = intval($cid); } catch (Exception $e) { echo 'error request!'; exit; } $curCate = Cate::find($cid); //检查分类合法性 if (!is_object($curCate)) { return Response::make('cate not exist', 404); } //当前用户id; $uid = $curCate->uid; //根据uid查找用户信息 $user = User::find($uid); //根据关联模型查找当前用户所有分类 $cates = $user->getCate; //查找用户当前分类下的文章列表,分页显示 $articles = Article::where('cid', $cid)->where('uid', $uid)->where('status', 1)->paginate(2); //户当前分类下的文章总数 $count = Article::where('cid', $cid)->where('uid', $uid)->where('status', 1)->count(); //查找最新文章 $recoment = Article::where('uid', $uid)->where('status', 1)->orderBy('updated_at')->take(5)->get(); return View::make('blog.cate', compact('articles'))->with('user', $user)->with('cates', $cates)->with('curCate', $curCate->name)->with('count', $count)->with('recoment', $recoment); }
Route::get('/mailcontents', "MailcontentController@index"); Route::get('/delmailcontents/{id}', "MailcontentController@del"); Route::get('/mailcontents/create', "MailcontentController@create"); Route::get('/mailcontent/{id}', "MailcontentController@edit"); Route::post('/mailcontentsStore', "MailcontentController@store"); Route::post('/mailcontentsUpdate', "MailcontentController@update"); //CategoryController Route::get('/delCategory/{id}', "CategoryController@delCategory"); Route::get('/categories', "CategoryController@index"); Route::get('/categories/create', "CategoryController@create"); Route::get('/category/{id}', "CategoryController@edit"); Route::post('/categoryStore', "CategoryController@categoryStore"); Route::post('/categoryUpdate', "CategoryController@categoryUpdate"); Route::get('/delCate', function () { $id = Input::get("id"); Cate::find($id)->delete(); }); }); Route::post('/delRateImage', function () { // print_r(Input::get() ); $rate = Rate::where("id", Input::get("id"))->update(array("image" => '')); if (Input::get("id") > 0) { return 1; } else { return 0; } // return View::make("frontend.hotcase"); }); // App::missing(function($exception) // { //
/** * @destroy */ public function destroy($id) { //权限检查,检查是否非法编辑,分类所有者是登录用户 $cate = Cate::find($id); $uid = $cate->uid; //获取uid if ($uid != Auth::id()) { return Redirect::to('user/login'); } //删除分类 //Cate::find($id)->delete();//按实例删除 Cate::destroy($id); //按住键删除 //修改改分类所属文章状态为0,修改分类为默认值0【可选操作】 Article::where('cid', $id)->update(array('cid' => 0, 'status' => 0)); return Redirect::route('cate.index')->with('message', '分类删除成功!'); }