leandreaci / laravel-permission by leandreaci

A Simple permission check to laravel.
372
0
2
Package Data
Maintainer Username: leandreaci
Maintainer Contact: leandroandreaci@hotmail.com (Leandro Andreaci)
Package Create Date: 2016-10-13
Package Last Update: 2016-11-04
Language: PHP
License: MIT
Last Refreshed: 2024-11-11 15:01:57
Package Statistics
Total Downloads: 372
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel Permission

Laravel 5.3

At the moment the package is not unit tested, but is planned to be covered later down the road.

Quick Installation

Begin by installing the package through Composer. The best way to do this is through your terminal via Composer itself:

composer require leandreaci\laravel-permission:dev-master

Or add to you composer.json and run composer install.

"require": {
   "Foo/Bar" : "*",
   "leandreaci/laravel-permission": "dev-master"
},

Once this operation is complete, simply add the service provider to your project's config/app.php file and run the provided migrations against your database.

Service Provider

Leandreaci\LaravelPermission\LaravelPermissionServiceProvider::class

in the providers array and

'Permission' => Leandreaci\LaravelPermission\Facade\LaravelPermission::class,

Migrations

You'll need to run the provided migrations against your database. Publish the migration files using the vendor:publish Artisan command and run migrate:

php artisan vendor:publish
php artisan migrate

Using

1 - Add permission slug to permissions table. 2 - Add user and permission equivalent to permission_user table. 3 - Add Authorizable Trait to your User Model( Example above: Laravel 5.3).

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Leandreaci\LaravelPermission\Traits\Authorizable;

class User extends Authenticatable
{
    use Notifiable;
    use Authorizable;

4 - Check any method of your controller


    use Leandreaci\LaravelPermission\Facade\Permission;

    class FooController
    {
        public function index()
        {
            if(! Permission::can('view.foo'))
            {
                //do what you want ;)
            }
        }
    }