Created
April 22, 2016 13:47
-
-
Save NemanyaM/b0d25cd6877a2d450f1497252c4b8e78 to your computer and use it in GitHub Desktop.
This file contains 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 | |
namespace App\Http\Controllers; | |
use App\Post; | |
use Illuminate\Http\Request; | |
class PostsController extends Controller | |
{ | |
public function index() | |
{ | |
$posts = Post::all(); | |
$post = new Post; | |
return view('posts.index', compact('posts', 'post')); | |
} | |
public function create(Request $request) | |
{ | |
$data = $request->only('title', 'body'); | |
Post::create($data); | |
return redirect('/'); | |
} | |
public function edit($postId) | |
{ | |
$post = Post::where('id', $postId)->first(); | |
return view('posts.edit', compact('post')); | |
} | |
public function update(Request $request, $postId) | |
{ | |
$post = Post::where('id', $postId)->first(); | |
$data = $request->only('title', 'body'); | |
$post->update($data); | |
return redirect('/'); | |
} | |
public function delete($postId) | |
{ | |
$post = Post::where('id', $postId)->first(); | |
$postId->delete(); | |
return redirect('/'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment