Created
March 31, 2014 06:29
-
-
Save Rokt33r/9886439 to your computer and use it in GitHub Desktop.
Laravel 基礎 Lesson 6 - RESTful (app/controllers/PostController.php)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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