1. Go to this page and download the library: Download actengage/roles 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/ */
actengage / roles example snippets
Gate::define('sudo', function ($user, $model) {
return $user->hasRole(Role::findByName('account_owner'));
});
namespace App\Policies;
use App\User;
use App\Post;
class PostPolicy
{
/**
* If the user an account owner, the policy should always pass.
*
* @param \App\User $user
* @param \App\Post $ability
* @return bool
*/
public function before($user, $ability)
{
// isSuperAdmin() is a helper function provided by the Roleable trait.
// Which is a shortcut to: $user->hasRole(Role::findByName('account_owner'));
if ($user->isSuperAdmin()) {
return true;
}
}
/**
* Determine if the given post can be updated by the user.
*
* @param \App\User $user
* @param \App\Post $post
* @return bool
*/
public function update(User $user, Post $post)
{
return $user->id === $post->user_id;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.