Skip to content

Instantly share code, notes, and snippets.

@rawaludin
Created October 19, 2017 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rawaludin/3723fd5558258d89b80a8a61beea3c47 to your computer and use it in GitHub Desktop.
Save rawaludin/3723fd5558258d89b80a8a61beea3c47 to your computer and use it in GitHub Desktop.
@rawaludin
Copy link
Author

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