Skip to content

Instantly share code, notes, and snippets.

@pringgojs
Created October 22, 2018 14:50
Show Gist options
  • Save pringgojs/631ddf388780709dc2bfb060aa071386 to your computer and use it in GitHub Desktop.
Save pringgojs/631ddf388780709dc2bfb060aa071386 to your computer and use it in GitHub Desktop.
Blog controller -> sharing laravel
<?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