Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.1 @can, how use OR clause

I did not find how to use a clause (OR, AND) in view with @can, for checking multiple abilities ...

I tried:

@can(['permission1', 'permission2'])  @can('permission1' or 'permission2') @can('permission1' || 'permission2') 

But dont work ;(

like image 779
Marcaum54 Avatar asked Dec 09 '15 20:12

Marcaum54


People also ask

What is the use of @CAN in laravel?

##Permissions This package doesn't add any permission-specific Blade directives. Instead, use Laravel's native @can directive to check if a user has a certain permission. You can use @can , @cannot , @canany , and @guest to test for permission-related access.

How do you use Auth in laravel?

Introduction. Want to get started fast? Install the laravel/ui Composer package and run php artisan ui vue --auth in a fresh Laravel application. After migrating your database, navigate your browser to http://your-app.test/register or any other URL that is assigned to your application.

How do you check Auth in laravel blade?

Try use: auth()->check() , \Auth::check() , or remove all views in /var/www/html/laravel-master/storage/framework/views/ . Show activity on this post.

Where is the Auth folder in laravel?

The authentication configuration file is located at config/auth. php , which contains several well documented options for tweaking the behavior of the authentication services. At its core, Laravel's authentication facilities are made up of "guards" and "providers".


2 Answers

You can use the Gate facade:

@if(Gate::check('permission1') || Gate::check('permission2'))  @endif 
like image 195
tommy Avatar answered Sep 19 '22 16:09

tommy


The @canany blade directive has been added to Laravel v.5.6.23 on May 24, 2018

Usage:

@canany(['edit posts', 'delete posts'])     <div class="actions">         @can('edit posts')             <button>Edit post</button>         @endcan         @can('delete posts')             <button>Delete post</button>         @endcan     </div> @endcanany 
like image 40
Jasper Briers Avatar answered Sep 19 '22 16:09

Jasper Briers