欢迎各位兄弟 发布技术文章
这里的技术是共享的
use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Page; use Redirect, Input, Auth; class PagesController extends Controller { /** * Show the form for creating a new resource. * * @return Response */ public function create() { return view('admin.pages.create'); } /** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $this->validate($request, [ 'title' => 'required|unique:pages|max:255', 'body' => 'required', ]); $page = new Page; $page->title = Input::get('title'); $page->body = Input::get('body'); $page->user_id = 1;//Auth::user()->id; if ($page->save()) { return Redirect::to('admin'); } else { return Redirect::back()->withInput()->withErrors('保存失败!'); } } /** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { return view('admin.pages.edit')->withPage(Page::find($id)); } /** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Request $request,$id) { $this->validate($request, [ 'title' => 'required|unique:pages,title,'.$id.'|max:255', 'body' => 'required', ]); $page = Page::find($id); $page->title = Input::get('title'); $page->body = Input::get('body'); $page->user_id = 1;//Auth::user()->id; if ($page->save()) { return Redirect::to('admin'); } else { return Redirect::back()->withInput()->withErrors('保存失败!'); } } /** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $page = Page::find($id); $page->delete(); return Redirect::to('admin'); } }