Last active
February 22, 2020 06:48
-
-
Save rizkhal/6726754876ad1cb31708bd3ef87e5de6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Illuminate\Http\Request; | |
use App\Http\Requests\PostRequestValidate; | |
use App\Repositories\PostRepositoryInterface as PostEloquent; | |
class PostController extends Controller | |
{ | |
protected $eloquent; | |
public function __construct(PostEloquent $eloquent) | |
{ | |
$this->eloquent = $eloquent; | |
} | |
public function index() | |
{ | |
$posts = $this->eloquent->paginate(); | |
return view('posts.index', compact('posts')); | |
} | |
public function create() | |
{ | |
return view('posts.create'); | |
} | |
public function store(PostRequestValidate $request) | |
{ | |
if($this->eloquent->save($request->data())) { | |
notice('success', 'Berhasil menyimpan postingan'); | |
return back(); | |
} | |
return back(); | |
} | |
public function edit($slug) | |
{ | |
$post = $this->eloquent->findBySlug($slug); | |
return view('posts.edit', compact('post')); | |
} | |
public function update(PostRequestValidate $request, string $slug) | |
{ | |
if($this->eloquent->update($slug, $request->data())) { | |
notice('success', 'Berhasil mengubah postingan'); | |
return back(); | |
} | |
return back(); | |
} | |
public function destroy($slug) | |
{ | |
if($this->eloquent->delete($slug)) { | |
notice('success', 'Berhasil menghapus postingan'); | |
return back(); | |
} | |
return back(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment