public function edit($id) { $data["_title"] = array("top" => "編輯最新消息", "main" => "Home", "sub" => "post"); $data["active"] = "news"; $data["post"] = Post::find($id); $data["cates"] = Cate::where('type', '最新消息')->get()->toArray(); return View::make('admin.posts.edit', $data); }
public function categoryUpdate() { $id = Input::get("id"); $name = Input::get("name"); $type = Input::get("type"); $update_data = array('name' => $name, 'type' => $type); $user = Cate::where('id', $id)->update($update_data); // $user->username = $username; if ($user) { return Redirect::to('categories')->withInput()->with('success', '更新成功'); } else { return Redirect::to('category/' . $id)->withInput()->with('error', '更新失敗'); } }
<?php $cates = Cate::where('type', "工程進度")->whereNotIn('name', array('圖面下載'))->get(); $cates_array = array(); $cates_not = array(); foreach ($cates as $cate) { $cates_array[$cate->id] = $cate->name; $cates_not[$cate->id] = $cate->id; } $id = Input::get("id"); $rate = Rate::find($id); $dd1 = explode(" ", $rate->created_at); $dd = explode("-", $dd1[0]); $category_id = Input::get("category_id"); if (!empty($id)) { // print_r($cates_not); $pics = DB::table("rate_pics")->where('rate_id', $id)->whereIn('category_id', $cates_not)->get(); } else { $pics = DB::table("rate_pics")->first(); } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>工程進度</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="css/css.css"> <link rel="stylesheet" type="text/css" href="css/process.css">
/** * Remove the specified resource from storage. * * @param int $id * @return Response * articles/id/delete 自定义路由 */ public function destroy($id) { //删除文章标签[真实删除] // Tag::where('aid',$id)->delete(); //检查假删权限【文章uid为登录用户id,并且文章有分类cid!=0】 $obj = Article::find($id); if ($obj->cid == 0 || $obj->uid != Auth::id()) { return Redirect::route('articles.index')->with('error', '不被允许的非法操作!'); } //文章分类总数减1 $cid = Article::find($id)->cid; Cate::where('id', $cid)->decrement('count'); //更改文章分类和状态 Article::where('id', $id)->update(array('cid' => 0, 'status' => 0)); return Redirect::route('articles.index')->with('message', '删除成功!'); }
/** * @update */ public function update($id) { //数据验证 $rules = array('name' => 'required|min:2', 'desc' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::route('cate.edit', array('id' => $id))->withErrors($validator)->withInput(); } //检查是否非法编辑,分类所有者是登录用户 $cate = Cate::find($id); $uid = $cate->uid; //获取uid if ($uid != Auth::id()) { return Redirect::to('user/login'); } //检查修改的用户分类是否唯一 $count = Cate::where('name', Input::get('name'))->where('uid', Auth::id())->where('id', '<>', $id)->count(); if ($count == 0) { //执行更新操作 $cate->name = Input::get('name'); $cate->desc = Input::get('desc'); $cate->save(); return Redirect::route('cate.edit', array('id' => $id))->with('success', '修改成功!'); } else { return Redirect::route('cate.edit', array('id' => $id))->with('error', '分类不能重复!')->withInput(); } }