Skip to content

Instantly share code, notes, and snippets.

@Rokt33r
Created March 29, 2014 17:13
Show Gist options
  • Save Rokt33r/9858259 to your computer and use it in GitHub Desktop.
Save Rokt33r/9858259 to your computer and use it in GitHub Desktop.
Laravel 基礎 Lesson 4 - DB (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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment