V
V
vlad31442019-05-10 17:25:59
Laravel
vlad3144, 2019-05-10 17:25:59

How to properly declare gate in laravel?

In App\Providers\AuthServiceProvider.php I declare Gate

public function boot()
{
    $this->registerPolicies();

    Gate::define('delete_item', function ($user_role) {
          return $user_role === 'admin';
    });
}

In view I write:
@can('delete_item', $role)
код
@endcan

This rule doesn't work for me. With the help of var_dump($user_role) I looked at what the function turns out to be. It gave out not my variable, which I passed through "@can", but the user data that is stored in Auth.
What did I do wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2019-05-10
@Alex_Wells

Well, try reading the documentation. Who told you that the first variable in your callback will be yours?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question