1. Go to this page and download the library: Download beatswitch/lock-laravel 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/ */
use BeatSwitch\Lock\Manager;
return [
...
'permissions' => function (Manager $manager) {
// Set your configuration here.
$manager->alias('manage', ['create', 'read', 'update', 'delete']);
$manager->setRole('user', 'guest');
$manager->setRole(['editor', 'admin'], 'user');
},
];
use BeatSwitch\Lock\Callers\SimpleCaller;
use BeatSwitch\Lock\Drivers\ArrayDriver;
use BeatSwitch\Lock\Manager;
return [
...
'permissions' => function (Manager $manager) {
// Only set permissions beforehand when using the array driver.
if ($manager->getDriver() instanceof ArrayDriver) {
// Set some role permissions.
$manager->role('guest')->allow('read', 'posts');
$manager->role('user')->allow('create', 'posts');
$manager->role('editor')->allow('publish', 'posts');
// Set permissions for a specific user.
$manager->caller(new SimpleCaller('users', 1))->allow('publish', 'posts');
}
},
];
Lock::can('create', 'posts');
Lock::cannot('publish', $post);
// Or use the auth instance. This is possible because your User model has the LockAware trait.
Auth::user()->can('create', 'posts');