Skip to content

Instantly share code, notes, and snippets.

@Rokt33r
Created March 31, 2014 06:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rokt33r/9886439 to your computer and use it in GitHub Desktop.
Save Rokt33r/9886439 to your computer and use it in GitHub Desktop.
Laravel 基礎 Lesson 6 - RESTful (app/controllers/PostController.php)
<?php
class PostController extends BaseController{
function create(){
return View::make('posts.create');
}
function store(){
DB::table('posts')->insert([
'title'=>Input::get('title'),
'body'=>Input::get('body')
]);
return Redirect::to('posts');
}
function index(){
$posts = DB::table('posts')->get();
return View::make('posts.index')->with('posts', $posts);
}
function show($postid){
$post = DB::table('posts')->where('id', $postid)->first();
return View::make('posts.show')->with('post', $post);
}
function edit($postid){
$post = DB::table('posts')->where('id', $postid)->first();
return View::make('posts.edit')->with('post', $post);
}
function update($postid){
DB::table('posts')->where('id', $postid)
->update(['title'=>Input::get('title'), 'body'=>Input::get('body')]);
return Redirect::route('posts.show',[$postid]);
}
function destroy($postid){
DB::table('posts')->where('id', $postid)->delete();
return Redirect::route('posts.index');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment