1. Go to this page and download the library: Download ipunkt/permissions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ipunkt / permissions example snippets
<?PHP
namespace Example;
class ModelPermissionChecker extends PermissionChecker {
public function checkPermission(CanInterface $user, $action) {
// Give permission to do anything if the $user is the owner of this model
if( $user->getId() == $this->getEntity()->owner->getKey() )
return true;
// If the $user is not the owner, fall back to the usual permission management
return parent::checkPermission($user, $action);
}
}
class Model extends Eloquent implements HasPermissioninterface {
use HasPermissionTrait;
$checker_instance = 'Example\ModelPermissionChecker';
}
class User implements CanInterface {
use CanTrait {
CanTrait::can as _can;
};
public function can($action, HasPermissionInterface $object) {
$permission = false;
if($this->getKey() == 0)
$permission = true;
else
$permission = _can($action, $object);
return $permission;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.