CasperLaiTW / laravel-permission-packages by casperlaitw

Extend toddish verify permission to easy setting for Laravel 4.
53
0
2
Package Data
Maintainer Username: casperlaitw
Maintainer Contact: casper.lai@sleepingdesign.com (Casper Lai)
Package Create Date: 2013-10-20
Package Last Update: 2014-02-11
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-09 15:02:43
Package Statistics
Total Downloads: 53
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Easy Permission Verify - Laravel 4


It's a extend toddish verify permission to easy setting for Laravel 4.

  • a file organize all permission defined
  • Licensed under the MIT license

Important

This packages depends on toddish/veirfy. You should configurate toddish/verify.

Installation

Add verify to your composer.json file:

"require": {
	"casper/permission": "dev-master"
}

Now, run a composer update on the command line from the root of your project:

composer update

Registering the Package

Add the service provider to your config in app/config/app.php:

'providers' => array(
	'Casper\Permission\PermissionServiceProvider'
),

Set Package Aliases

Add the service Aliases to your config in app/config/app.php:

'aliases' => array(
	'Permission'      => 'Casper\Permission\PermissionFacade'
),

Usage

1. Define permissions in app/permission.php

Now, create a file called app/permission.php. The file will be loaded automatically.

// Permission::setPermission($route, $canUsePermissionName);
Permission::setPermission(array('admin.roles.index', 'admin.roles.show'), array('role_index', 'role_all'));

As you can see, the define include two param:

  • $route It's router name. It's can be array or string.
  • $canUsePermissionName It's means can use this page's permission name. It's can be array or string.

2. Run Verify

In you want to run verify place to add code:

	Permission::verify(Request::url());

Example: I want to verify after checking admin logged-in. So I place code in app/filters.php

Route::filter('auth.admin', function(){
	if(Auth::guest()) return Redirect::route('admin.login');
	// Permission Verify
	Permission::verify();
});