You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require boleiros/guardian
// config/bootstrap.php
Plugin::load('Guardian', ['bootstrap' => true, 'routes' => true]);
Or, in your terminal:
bin/cake plugin load -b -r Gardian
bin/cake migrations migrate --plugin Guardian
- import and use the Guardian Trait on your user Model
//User.php
<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
use Guardian\Model\Traits\Guardian;
class User extends Entity
{
use Guardian;
....
- call the method passing the name of the permission:
$user->hasPermission('users.index')