ge/lararole

"User Roles and permissions for the system"

dev-master 2018-06-28 20:37 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:55:17 UTC


README

Lararole is the package to manage user's roles and permissions for your website/blog/website by using this package you will have role and permissions module where you can define as many role as you want along with permissions as well as you can easily customize theme as per your theme requirements.

Please Note this package will assume you are already using laravel authentication system and you have already users table in your database

Installation

In order to use Laravel firstly, pull in the package through Composer

composer require ge/lararole

you can also add this package in your project's composer.json file.

"require": {
  "Ge/Lararole": "1.*",
}

after adding package in composer.json you will need to update composer

composer update

And then include the service provider within app/config/app.php

'providers' => [
    Ge\Lararole\LararoleServiceProvider::class
];

If you are in laravel 5.6 then skip the last step laravel auto discover feature will be add automatically

Run Migration

php artisan migrate

This will generate necessary database tables

Make User model Rolable

Open User Model and add rolable trait on it.

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Ge\Lararole\Ge\Rolable;

class User extends Authenticatable
{
    use Notifiable, Rolable;
}

You are all set

Now you can user the package

All available Routes

Template Customization

Of-course you want to customize template as per your site theme, you can override the template by publish vendor to your views directory

php artisan vendor:publish --provider=Ge\Lararole\LararoleServiceProvider::class --tag=views

Useful methods

// all the roles has assigned to this user

$user = User::find(1);

foreach($user->roles as $role)
{
    echo $role->name . '</br>';
}


// list all the permissions has in role with ID 1

$role = Role::find(1);

foreach($role->permissions as $permission)
{
    echo $permission->name . '</br>';
}

Happy coding...