PHPackages                             otifsolutions/aclmenu - 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. otifsolutions/aclmenu

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

otifsolutions/aclmenu
=====================

An ACL Menu Package that includes User Roles, Permissions, Db based Menu Items, rights and permission based menu items

1.1.2(1y ago)11.9k↑462.5%1MITPHP

Since May 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/otifsolutions/aclmenu)[ Packagist](https://packagist.org/packages/otifsolutions/aclmenu)[ RSS](/packages/otifsolutions-aclmenu/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (15)Used By (0)

aclmenu
=======

[](#aclmenu)

### Requirements

[](#requirements)

```
PHP 5 > 5.3.0

```

```
Laravel > 5.0

```

### How to install the library

[](#how-to-install-the-library)

Install via Composer

**Using Composer (Recommended)**

Either run the following command in the root directory of your project:

```
 composer require otifsolutions/aclmenu

```

### Usage

[](#usage)

1. Create User Role ( via Seeder )

    ```
    UserRole::updateOrCreate(
        ['id' => 1],[
           'name' => 'ADMIN'
        ]);
    ```
2. Create Menu Items for Created `UserRole`.

    ```
    $id = UserRole::Where(['name' => 'ADMIN'])->get('id');
    MenuItem::updateOrCreate(
     ['id' => 1], [
         'order_number'=> 1,
         'parent_id' => null,
         'icon' => 'feather icon-home',
         'name' => 'dashboard',
         'route' => '/dashboard',
         'generate_permission' => 'ALL'
      ])
         ->user_roles()
         ->sync($id);
    ```

    `$id` is id of user role that is admin.

    OptiontypeDescription`order_number`INTNumber to show the item in sequence.`parent_id`INTId of any item as a parent menu item.`icon`VarcharIcon of created menu item.`name`VarcharShow the name of created menu item.`route`VarcharRoute access the intended page.
    - `generate_permission` is `ENUM` type of granted permission to the User Role, that are 'ALL', 'MANAGE\_ONLY', 'READ\_ONLY'.

    OptionDescriptionAllAllow user role to create, read, update, delete.MANAGE\_ONLYAllow user role manage.READ\_ONLYshow that User can only read.
3. - User role and permissions are created.
    - Sync the permissions against menu items, so that user can have permissions to access the menu items.

    ```
    {
    $userRole = UserRole::where(['name' => 'ADMIN'])->first();
    $permissions = Permission::whereIn('menu_item_id',$userRole->menu_items()->pluck('id'))->pluck('id');
    $userRole->permissions()->sync($permissions);
    }
    ```
4. Register the artisan command in database seeder in App/Database/Seeder/DatabaseSeeder.php;

    ```
    Artisan::call('aclmenu:refresh');

    ```

    Seeder run in this sequence.

    ```
    $this->call(UserRolesTableSeeder::class);
    $this->call(MenuItemsTableSeeder::class);
    $this->call(UserTableSeeder::class);
    $this->call(TeamsTableSeeder::class);
    Artisan::call('aclmenu:refresh');
    $this->call(DefaultUserPermissionsSync::class);

    ```
5. Run the seeder to implement the changes

    ```
    php artisan db:seed

    ```

#### aclmenu:refresh

[](#aclmenurefresh)

- This command seeds data in `Permission` model after checking the permission in `MeuItem` model.
- Possible permissions are 'All', "READ" and "MANAGE\_ONLY".
- Default permission is `READ`.

#### ACLUserTrait

[](#aclusertrait)

- **Use `OTIFSolutions\ACLMenu\Traits\ACLUserTrait` in `User` model**
- **Following methods are used in this trait**

    MethodrelationDescriptionuser\_roleone-to-many (Inverse)This method returns user role from `UserRole` model to which user belongs.groupone-to-many (Inverse)This method returns group from `UserRoleGroup` model to which user belongs.parent\_teamone-to-many (Inverse)This method returns parent\_team from `Team` model to which it belongs.child\_teamone-to-oneThis method returns user who created the team.

- **team**

    This method returns the user who created the team or parent\_team.
- **hasPermission**

    **This method checks if the user has permission or not to access the page.**

    ```
       if (!Auth::user()->hasPermission('READ', '/dashboard'))
           return 'error';
       return view('dashboard');
    ```

    - Returns `True` if condition is true otherwise return `false`.
    - Two Attributes are passed when calling the method.
    - One is `permissionTypeString`, possible values are READ, CREATE, UPDATE, or DELETE.
    - If no permissionTypeString is passed, READ is considered default.
    - Another attribute is `permission`, which is the route of page.
    - If no permission is passed, current permission is stored in session.
- **hasPermissionMenuItem**

    - This method checks if the user has permission or not to access the menu item.
    - Id of menu item is passed `menu_item_id`.
    - Boolean value is returned. Possible values ar true or false.
- **getTeamOwnerAttribute**

    This method returns team owner from the team. return `$this['team']['owner']`

### Config

[](#config)

- Returns `redirect_url` if user is unauthorized e.g. `/`

    ```
     if ($request->user() == null)
     return redirect(config('laravelacl.redirect_url'));
    ```
- It has a path of laravel `config.php` which returns the user from model.

    ```
     'models' => [
         'user'   => config('auth.providers.users.model')
     ]
    ```
- Use this code to use config. `config('laravelacl.models.user')`

### Middleware

[](#middleware)

- Middleware handles the incoming request.
- Middleware is set on route. such as

    ```
       Route::get('/dashboard', [DashboardController::class, 'dashboard'])->middleware('role:dashboard');
    ```
- If route has permission, intended page will be returned otherwise user is redirected.

#### How Middleware Works

[](#how-middleware-works)

- If `Auth::User` not found, homepage is returned. e.g. `/`
- **If permission is null**

    - Get the current path info for the request.

        `$permission = $request->path();`
    - Current permission is stored in the session using current path.

        ```
        \Session::put('current_permission', $permission);

        ```

### MODELS

[](#models)

- **MenuItem**

    MethoderelationDescriptionchildrenone-to-manyThis method returns submenu items from `MenuItem` model. One menuitem can have one or more child items.permissionsone-to-manyThis method returns list of permissions from `Permission` model. One menuitem can have one or more permissions.user\_rolesmany-To-manyThis method returns list of user\_roles that belong to `MenuItem`.
- **Permission**

    MethodrelationDescriptionmenu\_itemone-to-many (Inverse)This method return menuitem from `MenuItem` model that belongs to permission.typeone-to-many (Inverse)This method return permission type which belongs to permission.
- **PermissionType**

    - permission types has been created through seeder.
    - These types are "READ", "CREATE", "UPDATE", "DELETE" and "MANAGE".
- **Team**

    MethodrelationDescriptionownerone-to-many(Inverse)This method returns user who creates the team. A team can have only one owner.permissionsbelongToManyThis method returns list of permissions from `Permission` model that belongs to `Team`.membersone-to-manyThis method returns list of members. A team can have one or more members.user\_rolesone-to-manyThis method returns list of user\_roles from `UserRole` model. Team can have one or more user roles.
- **User Role**

    MethodrelationDescriptionpermissionsbelongsToManyThis method returns list of `permissions` from `Permission` model that belong to user\_role.menu\_itemsbelongsToManyThis method returns list of menu\_items from `MenuItem` belong with user\_role.teamone-to-many (Inverse)This method returns team which belongs to user role.usersone-to-manyThis method returns list of users from `User` model. A user role can one or more users.groupsbelongsToManyThis method returns groups that belong to UserRoleGroup.
- **UserRoleGroup**

    MethodrelationDescriptionusersone-to-manyThis method returns list of users object. One user role group can have one or more users.user\_rolesbelongsToManyThis method returns list of user\_roles from `UserRole` that belong with `UserRoleGroup` model.### Teams

    [](#teams)

**Step. 1**

- Team is created with a `user_id`.

    `Team::updateOrCreate(['user_id' => 1]);`

**Step. 2**

- Team owner creates user role.

**Step. 3**

- Owner assigns the permission to the created user role.
- Owner can assign the permission which are accessible by him.
- `Permission` is fetched from `Permission` model to assign permission,
- When owner assigns the permissions, these permissions will sync using following code.

    `$userRole->permissions()->sync($request['permissions']);`

**Step. 4**

- Team members can be added by using the created user role.

### Sidebar Creation

[](#sidebar-creation)

- Use the following class for side bar.

```

              Your Project Name

          Content of sidebar

```

### Content of sidebar

[](#content-of-sidebar)

- Sidebar is created using the permissions which are assigned.
- **If the user\_role is authenticated.**

    - Loop begins and checks if user has permission to access the menuitem.
    - Name of menu item appears on the sidebar.
- `Request::is` checks if the incoming request matches to the menuitem route then item becomes active. `Request::is(strtolower(str_replace('/','',$menuItem['route'])))`
- If any menu item has submenu item, it will be opened after matching the request.
- If user has permission to access menuitem, the loop starts and matching submenu item becomes active.

```

     @if(Auth::user()['user_role'])
      @foreach(Auth::user()['user_role']->menu_items()->orderBy('order_number', 'ASC')->get() as $menuItem)
        @if (Auth::user()->hasPermissionMenuItem($menuItem['id']))
          @if ($menuItem['show_on_sidebar'])
               @if($menuItem['heading'])

                         {{$menuItem['heading']}}

               @endif
               @if (count($menuItem['children']) == 0)
                  @if($menuItem['parent_id'] === 0)

                          {{ $menuItem['name'] }}

                  @endif
                  @else

                        {{ $menuItem['name'] }}

                         @foreach($menuItem['children'] as $child)
                           @if (Auth::user()->hasPermissionMenuItem($child['id']))

                                {{ $child['name'] }}

                           @endif
                         @endforeach

                  @endif
            @endif
          @endif
        @endforeach
       @endif

```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance47

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~166 days

Recently: every ~370 days

Total

14

Last Release

392d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f9aeabc454ee05b530e6234f1689a89e8f63bc766e647ad78bec54add4215b4?d=identicon)[otifsolutions](/maintainers/otifsolutions)

---

Top Contributors

[![junaidmaqbutt](https://avatars.githubusercontent.com/u/13379343?v=4)](https://github.com/junaidmaqbutt "junaidmaqbutt (8 commits)")[![mtayyab7725](https://avatars.githubusercontent.com/u/66251458?v=4)](https://github.com/mtayyab7725 "mtayyab7725 (8 commits)")

### Embed Badge

![Health badge](/badges/otifsolutions-aclmenu/health.svg)

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

###  Alternatives

[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)[illuminate/auth

The Illuminate Auth package.

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

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)[amocrm/amocrm-api-library

amoCRM API Client

182728.5k6](/packages/amocrm-amocrm-api-library)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)

PHPackages © 2026

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