Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
/ Roleable Public archive

Simple role based authorization for Laravel.

License

Notifications You must be signed in to change notification settings

martink635/Roleable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Roleable

Simple role management for Laravel by Model class and ID for Laravel 5.1

For Laravel 5.0 use the 1.0 branch. For laravel 4 use the 0.9 branch.

Install

Via Composer

{
    "require": {
        "koterle/roleable": "1.1.*"
    }
}

Update Composer:

composer update --dev

Once it completes, add the service provideer in your config/app.php.

Koterle\Roleable\RoleableServiceProvider::class

Usage

Publish the config file and the migrations. Make sure you set your User model and User ID type correctly.

php artisan vendor:publish

Run the migrations.

php artisan migrate

Add the CanTrait to the User model:

use CanTrait;

Fill up the database with the desired roles and permissions.

Now you can use (role name/permission, class, id):

if (Auth::user()->is('administrator', 'Company', 1)) { ... }
if (Auth::user()->can('manage_users', 'Company', 1)) { ... }
if (Auth::user()->cannot('delete_posts', 'Blog', 1)) { ... }

Auth::user()->attachRole('administrator', 'Company', 1);
Auth::user()->detachRole('administrator', 'Company', 1);

License

The MIT License (MIT)

About

Simple role based authorization for Laravel.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages