PHP code example of faithfm / laravel-simple-permissions
1. Go to this page and download the library: Download faithfm/laravel-simple-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/ */
faithfm / laravel-simple-permissions example snippets
'defined_permissions' => [
'use-app', // minimum permission to use the app
'admin-master', // master admin privilege
'view-assets', // access assets but not able to edit them
'edit-assets', // access assets and able to edit them
],
/**
* The permissions relationship should be eager-loaded.
*/
protected $with = ['permissions'];
/**
* Get the permissions for the user.
*/
public function permissions()
{
return $this->hasMany(\App\Models\UserPermission::class);
}
$LaravelAppGlobals = [
'user' => auth()->user(), # THIS IS THE IMPORTANT ONE
'guest' => auth()->guest(),
'other-stuff' => $myStuff,
...
];
return view('myview')->with('LaravelAppGlobals', $LaravelAppGlobals);
if (Gate::allows('use-app'))
if (auth()->user()->permissions->restrictions['file'] == 'restrictedfile')
// ALLOW/DENY STUFF FROM HAPPENING