PHPackages                             sehrgut/laravel-object-roles - 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. sehrgut/laravel-object-roles

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

sehrgut/laravel-object-roles
============================

Roles &amp; Permissions for Laravel where roles can be held in regard to a database object

v0.1.1(5y ago)32.7kMITPHP

Since Sep 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/sehrgutesoftware/laravel-object-roles)[ Packagist](https://packagist.org/packages/sehrgut/laravel-object-roles)[ RSS](/packages/sehrgut-laravel-object-roles/feed)WikiDiscussions master Synced yesterday

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

Laravel Object Roles
====================

[](#laravel-object-roles)

> Roles &amp; Permissions for Laravel where roles can be held in regard to a database object

Table of Contents
-----------------

[](#table-of-contents)

- [Why?](#why)
- [Disclaimer](#disclaimer)
- [Getting Started](#getting-started)
- [Documentation](#documentation)
    - [Create Roles &amp; Permissions](#create-roles--permissions)
    - [Assign Permissions to Roles](#assign-permissions-to-roles)
    - [Assign Roles to Users](#assign-roles-to-users)
    - [Check Permissions](#check-permissions)
- [License](#license)

Why?
----

[](#why)

There are plenty of packages that add ACL functionalities to a Laravel application. Yet, none of the existing solutions seems to allow us to assign roles to users with respect to an object. We often come across a use case where we do not only need to define global roles, such as `TECH_ADMIN`, but also roles in regard to a database object, such as an `Organisation`, which has eg. `EDITOR` users that are granted certain permissions only on that specific `Organisation` and not on others.

Disclaimer
----------

[](#disclaimer)

**This package is in its very early days. It currently makes quite a few assumptions:**

1. Users are stored in a `users` table
2. The `users` table already exists when installing the package and running the migrations
3. The `users` table has a primary key `id` which is an `unsigned integer`
4. Neither of the following tables exists before installing the package:
    - `roles`
    - `permissions`
    - `permission_role`
    - `role_user`

Getting Started
---------------

[](#getting-started)

### 1. Install Package

[](#1-install-package)

```
composer require sehrgut/laravel-object-roles
```

### 2. Run database migrations

[](#2-run-database-migrations)

```
php artisan migrate
```

### 3. Use `HasRolesAndPermissions` trait on the `User model

[](#3-use-hasrolesandpermissions-trait-on-the-user-model)

```
