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:
1// Having a user 2$user = User::first(); 3 4// Create a new marvel 5$storm = Spectre::create('storm')->havingPower([ 6 'weather_manipulation', 7 'earth_telepathy', 8 'high_sens', 9 'see_the_future'10]);11 12// we can grant a power to it13$storm = Spectre::of($storm)->grant('flying');14 15// Or take it off16$storm = Spectre::of($storm)->takeOff('see_the_future');17 18 19// bless the user with the abilities of the marvel20$user->cerebro()->blessWith($storm);21 22 23// check if it has the ability24$user->cerebro()->owns('weather_manipulation');25 26// check if it has one of the provided abilities27$user->cerebro()->ownsOneOf([28 'earth_telepathy',29 'flying',30 'x-ray',31]);32 33// make it human again (remove its role)34$user->cerebro()->humanize();
Further, here are more examples from the readme, demonstrating how to manage the instances directly:
1// Create Ability 2$ability = Ability::create([ 3 'super_power' => 'speed' 4]); 5 6// Create a Marvel 7$marvel = Marvel::create([ 8 'name' => 'Cristiano Ronaldo' 9]);10 11// Grant the ability12$marvel->grant($ability);13 14// remove a certain ability15$marvel->takeOff($ability);16 17// remove all and keep only those18$marvel->keep($abilities);19 20// bless it to our user21$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.
0 comments:
Post a Comment
Thanks