https://github.com/antonyagustine/roles-and-permission
laravel simple roles and permission
https://github.com/antonyagustine/roles-and-permission
laravel laravel-package permissions php rap roles
Last synced: 6 months ago
JSON representation
laravel simple roles and permission
- Host: GitHub
- URL: https://github.com/antonyagustine/roles-and-permission
- Owner: antonyagustine
- Created: 2018-06-06T05:34:45.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-03-29T03:28:58.000Z (over 4 years ago)
- Last Synced: 2025-11-27T16:25:03.724Z (7 months ago)
- Topics: laravel, laravel-package, permissions, php, rap, roles
- Language: CSS
- Size: 548 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
 [](https://packagist.org/packages/laravel/laravel) [](https://packagist.org/packages/laravel/laravel)
# Roles And Permission (RAP)
A simple package to assign RAP(Roles And Permission) for an application.
## Installation
Via composer
```
composer require "processdrive/rap":"dev-master"
```
Or set in composer.json
```
"require": {
"processdrive/rap":"dev-master"
}
```
## Register Dependencies
Set configuration in `config/app.php`
```
// Set providers.
'providers' => [
Collective\Html\HtmlServiceProvider::class,
processdrive\rap\RAPServiceProvider::class,
]
// Set aliases
'aliases' => [
'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',
'RAPHelper' => processdrive\rap\app\Helpers\RAPHelper::class,
],
```
Set relationship in `app/User.php`
```
/**
* @return @return \Illuminate\Database\Eloquent\Relations\belongsToMany
*/
public function roles() {
return $this->belongsToMany("App\Models\Role","user_role", "user_id", "role_id");
}
/**
* [hasPermission]
* @param [str] $permission
* @return boolean
*/
public function hasPermission($permission) {
return $this->roles()->get()[0]->hasPermission($permission);
}
```
## Publish the package
```
php artisan vendor:publish --all
```
## Configuration
Set configuration in `config/rap/rap_config.php`
```
return [
// Set Route access enable or disable
'use_package_routes' => true,
// Set middlewares
'middlewares' => ['auth', 'CheckRole'],
// Set Static Action
'static_action' => [
'index' => 'List',
'create' => 'Create',
'show' => 'Show',
'edit' => 'Edit',
'destroy' => 'Destroy',
'store' => 'Store',
'update' => 'Update',
'delete' => 'Delete'
],
//Set Omit Action it will be womited from permission module.
'omit_action' => []
];
```
## Run command
```
composer dump-autoload
```
## Run migration
```
php artisan migrate
```
## Generate translation and DB seed
```
php artisan rap_generate:translation
```
## Edit translation files
```
resources/lang/en/rap_actions.php
resources/lang/en/rap_modules.php
```
## Add Route
Add Route in `routes/web.php`
```
Route::group(['middleware' => 'CheckRole'], function () {
//add routes which are going to validate by RAP.
});
RAPHelper::routes();
```
## Add ifream in your application
Add ifream in your application
```
```
## Register Middelware
register in your `app/Http/kernel.php`
```
protected $routeMiddleware = [
'CheckRole' => processdrive\rap\app\Http\Middleware\CheckRole::class,
];
```
## Usage
```
@hasPermission("viewSettings")
// your code
@endHasPermission
```