Laravel Authorization Authorizing Actions with Gates


Example

To use the example above on a blade template to hide content from the user, you would typically do something like this:

@can('view-content', $content)
 <! -- content here -->
@endcan

To completely prevent navigation to the content, you can do the following in your controller:

if(Gate::allows('view-content', $content)){
    /* user can view the content */
}

        OR

if(Gate::denies('view-content', $content)){
    /* user cannot view content */
}

Note: You are not required to pass the currently authenticated user to these method, Laravel takes care of that for you.