PHPackages                             metko/metkontrol - 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. metko/metkontrol

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

metko/metkontrol
================

Pakage permission

016PHP

Since May 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/metko/metkontrol)[ Packagist](https://packagist.org/packages/metko/metkontrol)[ RSS](/packages/metko-metkontrol/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Simple personal package to handle roles &amp; permissions inside a Laravel app. Compatible with Laravel 5.8.

Installation
============

[](#installation)

Via composer:

```
composer require metko/metkontrol
```

Deploy the config &amp; migrations file

```
php artisan vendor:publish --provider="Metko\Metkontrol\MetkontrolServiceProvider"
```

And finaly make the migration

```
php artisan migrate
```

---

> Optionally, you can specify the firsts roles and permissions you want in the config file. By default, it will use the following ones :

```
'roles'  =>  ['Member',  'Author',  'Moderator',  'Admin',  'Super Admin'],

'permissions'  =>  ['A permission',  'Second permission',  'third permission'],
```

> Blockquote

Duplicate the seeder class file

```
php artisan vendor:publish --provider="Metko\Metkontrol\MetkontrolServiceProvider" --tag="seeds"
```

Run composer auto-load

```
composer dump-autoload
```

And seed!

```
php artisan db:seed --class=MetkontrolTableSeeder
```

Usage
=====

[](#usage)

Just add the traits to the model you want to have role and permissions. (Note that you can use only the Role if you want, but not the opposite).

```
use Metko\Metkontrol\MetkontrolRole,
	Metko\Metkontrol\MetkontrolPermission,
	Metko\Metkontrol\MetkontrolCache; // To update the cache when a model instance  is created or updated
```

Roles
-----

[](#roles)

### Attach a roles to a model

[](#attach-a--roles-to-a-model)

```
$role = Role::find(1);

$model->attachRole($role); // Role class

// or

$model->attachRole(1); // Role ID

$model->attachRole('Author')  // Role Name or slug

// You can also pass an array

$model->attachRole([$role,  1,  'author']);

// Or a piped string

$model->attachRole("role-name|2|moderator|Super admin");
```

### Remove roles

[](#remove-roles)

```
$role  =  Role::find(1);

$model->removeRole($role);

// or

$model->removeRole(1);

$model->removeRole('role name')  // Name or slug

// or

$model->removeRole([$role,  1,  'role name']);

$model->removeRole("1|Moderator");

// or

$model->removeRole();  // Will remove all the role
```

### Check if the model has a specific role

[](#check-if-the-model-has-a-specific-role)

```
$role  =  Role::find(1);

$model->attachRole($role);

$model->hasRole($role);  // True

// or

$model->hasRole(1);  // True
$model->hasRole("Author");  // True
$model->hasRole("author");  // True

$model->hasRole('wrong role name')  // False
```

### Check if the model has one of the role

[](#check-if-the-model-has-one-of-the-role)

```
$model->hasAnyRole('test|3|a-slugged-role');
```

### Check if the model has all the given role

[](#check-if-the-model-has-all-the-given-role)

```
$model->hasAllRoles([$role, 3, "A new role"]);
```

Permissions
-----------

[](#permissions)

### Give permissions to a moddel

[](#give-permissions-to-a-moddel)

```
$permission  =  Permission::find(1);

$model->givePermissionTo($permission);
```

> Like for the role, you can p.ass an ID, a name, a slug, an array of mixed elements (string, model, int) or a piped string

### Remove permissions

[](#remove-permissions)

```
$model->removePermissionTo('permission name')  // Name or slug

// or

$model->removePermissionTo('permission1 name|permission2 slug');

$model->removePermissionTo([$permission1,  $permission2]);

$model->removePermissionTo(); // Will remove all the permission
```

### Check if it has a specific permission

[](#check-if-it-has-a-specific-permission)

```
$model->hasAnyPermission($permission1)  // Return bool
```

Or

```
$model->hasPermissionTo($permission1)  // Return bool
```

If it has one of the permissions

```
$model->hasAnyPermission("permission1|another-one|4")  // Return bool
```

If it has all the permission

```
$model->hasAllPermissions([$permission1, "second-permission"])  // Return bool
```

You can also check if the model have a specific permission directly from the permission model or the role model

```
$model->hasDirectPermission($permission1)  // Return bool

$model->hasDirectPermissionViaRole($permission1)  // Return bool
```

Middlewares
-----------

[](#middlewares)

You can use the middleware to check if the user has the given roles

```
Route::get('/', 'homeController@index')->middleware('hasRole:author');
Route::get('/', 'homeController@index')->middleware('hasRole:author|writer');
```

Or a permission

```
Route::get('/', 'homeController@index')->middleware('hasPermission:delete-account');
Route::get('/', 'homeController@index')->middleware('hasPermission:create-news|edit-blog');
```

Blades
------

[](#blades)

You can use blade template to check if the user has a role

```
@role('author')
// Only author can see it
@elserole('member')
// Only member can see it
@endrole
```

You can use blade template to check if the user has a one of the roles

```
@hasanyrole('author|3') // you can also pass a array
// Only author and role with ID to 3 can see it
@endhasanyrole
```

You can use blade template to check if the user has all the role

```
@hasallrole('author|3') // you can also pass a array
// Only author and role with ID to 3 can see it
@endhasallrole
```

You can use blade template to check if the user has all the role

```
@unlessrole(1) // you can also pass a array
// People without the role 1 can see this line
@endunlessrole
```

Or a permission

```
Route::get('/', 'homeController@index')->middleware('hasPermission:delete-account');
Route::get('/', 'homeController@index')->middleware('hasPermission:create-news|edit-blog');
```

Or both

```
Route::get('/', 'homeController@index')->middleware('hasRoleOrPermission:delete-account');
Route::get('/', 'homeController@index')->middleware('hasRoleOrPermission:create-news|Author');
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Metko](https://github.com/metko)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/30b4b1040670384e41adf76a63da5ec63503721dd2ca0fc95efd23e456d5590b?d=identicon)[metko](/maintainers/metko)

---

Top Contributors

[![metko](https://avatars.githubusercontent.com/u/7676725?v=4)](https://github.com/metko "metko (14 commits)")

### Embed Badge

![Health badge](/badges/metko-metkontrol/health.svg)

```
[![Health](https://phpackages.com/badges/metko-metkontrol/health.svg)](https://phpackages.com/packages/metko-metkontrol)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
