Created
October 19, 2017 06:19
-
-
Save rawaludin/3723fd5558258d89b80a8a61beea3c47 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
Sesi 3 BDV |
app/Providers/AuthServiceProvider.php
use App\Post;
use App\Policies\PostPolicy;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
Post::class => PostPolicy::class
];
app/Policies/PostPolicy.php
public function update(User $user, Post $post)
{
if ($user->isAdmin()) {
return true;
}
return $post->author_id == $user->id;
}
app/Policies/PostPolicy.php
public function delete(User $user, Post $post)
{
if ($user->isAdmin()) {
return true;
}
return $post->author_id == $user->id;
}
app/Http/Controllers/PostController.php
public function destroy(Post $post)
{
$this->authorize('delete', $post);
$post->delete();
return redirect()->route('posts.index');
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
resources/views/errors/403.blade.php