PHPackages                             ktourvas/rolesandperms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. ktourvas/rolesandperms

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

ktourvas/rolesandperms
======================

Laravel package

v1.3.3(3y ago)0735↓50%MITPHPCI failing

Since Nov 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ktourvas/rolesandperms)[ Packagist](https://packagist.org/packages/ktourvas/rolesandperms)[ RSS](/packages/ktourvas-rolesandperms/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (10)Used By (0)

rolesandperms
=============

[](#rolesandperms)

A simple laravel package to help you manage user roles and authorisation within a Laravel based application.

installation
------------

[](#installation)

Using composer:

```
$ composer require ktourvas/rolesandperms
```

after installation run

```
$ php artisan migrate
```

four tables are going to be created

- rap\_roles
- rap\_user\_roles
- rap\_model\_permissions
- rap\_record\_permissions

Update App\\User model with the HasPermissions and/or HasRoles traits depending on individual needs.

```
use ktourvas\rolesandperms\Entities\HasPermissions;

class User extends Authenticatable
{
    use  HasRoles, HasPersmissions, Notifiable;
```

HasRoles trait
--------------

[](#hasroles-trait)

Provides the user model with a roles() ManyToMany relationship to the Role model

```
$user->roles()->sync([
   Role::where('name', 'admin')->first()->id
]);
```

and a check method, returning true or false on the specified role.

```
$user->userIs('admin');
// boolean
```

HasPermissions trait
--------------------

[](#haspermissions-trait)

the trait provides the user model with a permissions onetoMany relation and extra wrapper methods for viewAny, view, create, update, delete, restore and forceDelete permission defaults. All of the above permission methods will result the equivalent table entries for the current user. The trait methods can then be used within any policy class in an application.

```
