Created
October 22, 2018 14:50
-
-
Save pringgojs/631ddf388780709dc2bfb060aa071386 to your computer and use it in GitHub Desktop.
Blog controller -> sharing laravel
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\Blog; | |
use Illuminate\Http\Request; | |
class BlogController extends Controller | |
{ | |
public function index() | |
{ | |
$blogs = Blog::all(); | |
return $blogs; | |
} | |
public function edit($id) | |
{ | |
$blog = Blog::find($id); | |
return $blog; | |
} | |
public function store(Request $request) | |
{ | |
$blog = new Blog; | |
$blog->title = $request->input('title'); | |
$blog->content = $request->input('content'); | |
$blog->save(); | |
return $blog; | |
} | |
public function update(Request $request, $id) | |
{ | |
$blog = Blog::findOrFail($id); | |
$blog->title = $request->input('title'); | |
$blog->content = $request->input('content'); | |
$blog->save(); | |
return $blog; | |
} | |
public function destroy($id) | |
{ | |
$blog = Blog::findOrFail($id); | |
$blog->delete(); | |
return 'success'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment