PHPackages                             samchentw/permission - 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. samchentw/permission

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

samchentw/permission
====================

4.0.0(4y ago)0160MITPHPPHP ^7.4|^8.0

Since Sep 5Pushed 4y agoCompare

[ Source](https://github.com/samchentw/permission)[ Packagist](https://packagist.org/packages/samchentw/permission)[ RSS](/packages/samchentw-permission/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (17)Used By (0)

Permission
==========

[](#permission)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1e0ad1acdc39bb4705d2de6b45fa2b10df6db808bd5e8635fed2c896dd43c3b1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d6368656e74772f7065726d697373696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samchentw/permission)[![tests](https://github.com/samchentw/permission/actions/workflows/tests.yml/badge.svg)](https://github.com/samchentw/permission/actions/workflows/tests.yml)
1.create roles table
2.permission management
3.Automatically register Laravel Gate

Installation
------------

[](#installation)

`composer require samchentw/permission`

Laravel
-------

[](#laravel)

Publish the config file by running:

```
$ php artisan vendor:publish --provider="Samchentw\Permission\PermissionServiceProvider"
```

Create the database table required for this package.

```
$ php artisan migrate
```

Run seed, If you want to modify the seed information, please go to data/roles.json

```
$ php artisan db:seed --class=RoleSeeder
```

User table add Role
-------------------

[](#user-table-add-role)

In the Model

```
    use Samchentw\Permission\Traits\Supports\HasRoles;

    class User extends Authenticatable
    {
        use HasApiTokens;
        use HasFactory;
        use HasProfilePhoto;
        use Notifiable;
        use TwoFactorAuthenticatable;
        use HasRoles;
```

Usage
-----

[](#usage)

```
    $user = User::whereId(1);
    // Adding roles to a user
    $rolesIds = [ 1, 2, 3];
    $user->addRolesByIds($rolesIds);

    // remove roles
    $user->deleteRoleByIds($rolesIds);

    // Syncing Associations
    $user->syncRoleByIds($rolesIds);
```

Registered access
-----------------

[](#registered-access)

In the config/permissionmap.php

For example:

```
  "groups" => [
        "pages" => [
            [
                'label' => '角色管理',
                'key' => 'Page.Role',
                'permissions' => ['Create']
            ]
        ],

        "features" => [
            [
                'group' =>'身分權限',
                'label' => '系統-管理員',
                'key' => 'Identity.Admin'
            ],
            [
                'group' =>'身分權限',
                'label' => '系統-會員',
                'key' => 'Identity.Member'
            ]
        ]
    ]
```

Gate will be automatically registered.

```
    $enable = config('permissionmap.enable', false);
    Gate::define("Page.Role", function (User $user) use ($enable) {
        $permission = collect($user->allPermission());
        $check = $permission->contains("Page.Role");
        if (!$enable) return true;
        return $check ? Response::allow() : Response::deny(trans('messages.not_permission'));
    });

     Gate::define("Page.Role.Create", function (User $user) use ($enable) {
        $permission = collect($user->allPermission());
        $check = $permission->contains("Page.Role.Create");
        if (!$enable) return true;
        return $check ? Response::allow() : Response::deny(trans('messages.not_permission'));
    });

    Gate::define("Identity.Admin", function (User $user) use ($enable) {
        $permission = collect($user->allPermission());
        $check = $permission->contains("Identity.Admin");
        if (!$enable) return true;
        return $check ? Response::allow() : Response::deny(trans('messages.not_permission'));
    });

    Gate::define("Identity.Member", function (User $user) use ($enable) {
        $permission = collect($user->allPermission());
        $check = $permission->contains("Identity.Member");
        if (!$enable) return true;
        return $check ? Response::allow() : Response::deny(trans('messages.not_permission'));
    });
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~12 days

Recently: every ~36 days

Total

16

Last Release

1585d ago

Major Versions

1.3.0 → 2.0.02021-09-08

2.5.2 → 4.0.02022-03-01

PHP version history (2 changes)1.0.0PHP ^7.3|^8.0

4.0.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/89454932?v=4)[samchentw](/maintainers/samchentw)[@samchentw](https://github.com/samchentw)

---

Top Contributors

[![samchentw](https://avatars.githubusercontent.com/u/89454932?v=4)](https://github.com/samchentw "samchentw (23 commits)")

---

Tags

laravelpermissionsroles

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/samchentw-permission/health.svg)

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

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.3M17](/packages/kartik-v-yii2-password)[vitalybaev/laravel5-dkim

Laravel 5/6 package for signing outgoing messages with DKIM.

3163.1k](/packages/vitalybaev-laravel5-dkim)

PHPackages © 2026

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