Skip to content

Instantly share code, notes, and snippets.

@Rokt33r
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rokt33r/9950671 to your computer and use it in GitHub Desktop.
Save Rokt33r/9950671 to your computer and use it in GitHub Desktop.
Laravel 基礎 Lesson 7 - Model(Eloquent) (app/controllers/PostController.php)
<?php
class PostController extends BaseController{
function create(){
return View::make('posts.create');
}
function store(){
Post::create(Input::all());
return Redirect::to('posts');
}
function index(){
$posts = Post::all();
return View::make('posts.index')->with('posts', $posts);
}
function show($postid){
$post = Post::find($postid);
return View::make('posts.show')->with('post', $post);
}
function edit($postid){
$post = Post::find($postid);
return View::make('posts.edit')->with('post', $post);
}
function update($postid){
$post = Post::find($postid);
$post->fill(Input::all());
$post->save();
return Redirect::route('posts.show',[$postid]);
}
function destroy($postid){
Post::find($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