My Blog Posts

Laravel Permissions Pack

Laravel Permissions Pack


Maravel Permissions is a package by Inani El Houssain that provides permissions on Laravel using a super user. This package helps you give users capabilities.

Because each user deserves to be a user, the Maravel API is based on the super user:

Having a user
$user = User::first();
// Create a new marvel
$storm = Spectre::create('storm')-havingPower([
'weather_manipulation',
'earth_telepathy',
'high_sens',
'see_the_future'
]);
// we can grant a power to it
$storm = Spectre::of($storm)->grant('flying');
// Or take it off
$storm = Spectre::of($storm)->takeOff('see_the_future');
// bless the user with the abilities of the marvel
$user->cerebro()--blessWith($storm);
// Check if it has the ability
$user->cerebro('weather_manipulation'owns');
// Check if it has one of the provided abilities
$user->cerebro()-ownsOneOf([
'earth_telepathy',
'flying',
'x-ray',
]);
// make it human again (remove its role)
$user->cerebro()->humanize();

Also, an example of how to manage instances directly:

Create Ability
$ability = Ability::create([
'super_power' => 'speed'
]);
// Create a Marvel
$marvel = Marvel::create([
'name' => 'Cristiano Ronaldo'
]);
// Grant the ability
$marvel->grant($ability);
// remove a certain ability
$marvel-$ability takeOff;
// remove all and keep only those
$marvel-$abilities;
// bless it to our user
$user---blessWith($marvel);

You can learn more about this package, get all setup instructions, and see the source code on GitHub at akiyamaSM/maravel-permissions.



Share this article


Comments (0)

Comment