hamedmehryar/laracancan

Resource Based Permission System for Laravel

Installs: 643

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 1

Open Issues: 0

Language:JavaScript

1.0.0 2016-10-08 09:44 UTC

This package is not auto-updated.

Last update: 2024-11-14 15:52:26 UTC


README

Screen Shot

LaraCanCan

Resource-Based permission system for laravel

Features

  • Resource Permissions
  • Permission Inheritance
  • Roles
  • Custom Permissions

Screen Shot

Screen Shot

Screen Shot

Installation (Laravel 5.x)

In composer.json:

"require": {
    "hamedmehryar/laracancan" "1.0.0"
}

Run:

composer update

Add the service provider to config/app.php under providers:

'providers' => [
    Hamedmehryar\Laracancan\LaracancanServiceProvider::class,
]

Create the Migration file:

php artisan laracancan:migration

Migrate your database:

php artisan migrate

Seed the Permissions:

php artisan laracancan:seed

Add the trait to your user model:

use Hamedmehryar\Laracancan\Traits\LaracancanUserTriat;

class User extends Model {
	use LaracancanUserTrait;
}

##usage

Permission checking:

Laracancan::canCreate('<resource-name>');
Laracancan::canRead('<resource-name>');
Laracancan::canUpdate('<resource-name>');
Laracancan::canDelete('<resource-name>');
Laracancan::can('<permission-name>', '<resource-name>');

$user->canCreate('<resource-name>');
$user->canRead('<resource-name>');
$user->canUpdate('<resource-name>');
$user->canDelete('<resource-name>');
$user->can('<permission-name>', '<resource-name>');

Role checking:

Laracancan::roles();
Laracancan::hasRole();

$user->roles();
$user->hasRole();

Getting Resources based on Permission:

Laracancan::creatableResources();
Laracancan::readableResources();
Laracancan::updatableResources();
Laracancan::deletableResources();
Laracancan::resourcesByPermission('<permission-name');

$user->creatableResources();
$user->readableResources();
$user->updatableResources();
$user->deletableResources();
$user->resourcesByPermission('<permission-name');

Attaching Roles to user:

$user->attachRole('<role-object>');
$user->detachRole('<role-object>');

$user->attachRoles('<roles>');
$user->detachRoles('<roles>');

Author