<?php
class BlogController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$blogs = Blog::all();
return View::make('blog.index')->with('blogs', $blogs);
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
return View::make('blog.create');
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$data = Input::all();
$blog = Blog::create(array(
'title' => Input::get('title'),
'author'=> Auth::user()->first,
'body' => Input::get('body')
));
if($blog->save())
{
return Redirect::route('blog.index');
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$post = Blog::find($id);
return View::make('blog.show')->with('post', $post);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$post = Blog::find($id);
return View::make('blog.edit')->with('post', $post);
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$data = Input::all();
$post = Blog::find($id);
//complete validation here
$post->title = Input::get('title');
$post->author = Auth::user()->first;
$post->body = Input::get('body');
if($post->save())
{
return Redirect::route('blog.index');
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
Blog::destroy($id);
Session::flash('message', 'You have successfull deleted a blog post');
return Redirect::route('blog.index');
}
}