Laravel - Authorization - Via Blade Templates

When writing Blade templates, you may wish to display a portion of the page only if the user is authorized to perform a given action. For example, you may wish to show an update form for a blog post only if the user can actually update the post. In this situation, you may use the @can and @cannot directives:

    
    @can('update', $post)
        
    @elsecan('create', App\Models\Post::class)
        
    @else
        
    @endcan
    
    @cannot('update', $post)
        
    @elsecannot('create', App\Models\Post::class)
        
    @endcannot
	

These directives are convenient shortcuts for writing @if and @unless statements. The @can and @cannot statements above are equivalent to the following statements:

    
    @if (Auth::user()->can('update', $post))
        
    @endif
    
    @unless (Auth::user()->can('update', $post))
        
    @endunless
	

You may also determine if a user is authorized to perform any action from a given array of actions. To accomplish this, use the @canany directive:

    
    @canany(['update', 'view', 'delete'], $post)
        
    @elsecanany(['create'], \App\Models\Post::class)
        
    @endcanany