Laravel Packages

Maravel Permissions Package for Laravel

Published
Maravel Permissions Package for Laravel image

Maravel Permissions is a package by Inani El Houssain that provides permissions in Laravel using superhero jargon. The package helps you grant users abilities, but in a fun, superhero kind of way.

Because every user deserves to be a hero, The Maravel API is based on superhero jargon:

// 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()->owns('weather_manipulation');

// 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();

Further, here are more examples from the readme, demonstrating how to manage the 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->takeOff($ability);

// remove all and keep only those
$marvel->keep($abilities);

// bless it to our user
$user->cerebro()->blessWith($marvel);

Tests are planned for this package, feel free to jump in and contribute. You can learn more about this package, get full installation instructions, and view the source code on GitHub at akiyamaSM/maravel-permissions.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
Slow Job Alerts and Replica Commit IDs in Laravel 13.40 image

Slow Job Alerts and Replica Commit IDs in Laravel 13.40

Read article
Flock: A Free, Native Herd Alternative for Laravel image

Flock: A Free, Native Herd Alternative for Laravel

Read article
Live Props for Real-Time Updates in Inertia.js v3.11 image

Live Props for Real-Time Updates in Inertia.js v3.11

Read article
Cooldown Dependency Policy now in Composer 2.11 image

Cooldown Dependency Policy now in Composer 2.11

Read article
Email Sending and Testing for Laravel in One Account image

Email Sending and Testing for Laravel in One Account

Read article
Decide with Jev: Tie Every AI Check to the Exact Draft image

Decide with Jev: Tie Every AI Check to the Exact Draft

Read article