PHPackages                             jmkim/laravel-entrust-gui - 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. jmkim/laravel-entrust-gui

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

jmkim/laravel-entrust-gui
=========================

GUI for Shanmuga's LaravelEntrust for Laravel 5+ (5, 6, 7, 8 and 9)

00PHPCI failing

Since Jun 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/jmkim/laravel-entrust-gui)[ Packagist](https://packagist.org/packages/jmkim/laravel-entrust-gui)[ RSS](/packages/jmkim-laravel-entrust-gui/feed)WikiDiscussions 6.x-and-above Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Entrust GUI
===========

[](#entrust-gui)

[![Code Climate](https://camo.githubusercontent.com/04c3d90584716a86d63a922084f1b4a810f6480ec9882adf55fccab5b42c8f34/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6a6d6b696d2f6c61726176656c2d656e74727573742d6775692f6261646765732f6770612e737667)](https://codeclimate.com/github/jmkim/laravel-entrust-gui)[![Build Status](https://camo.githubusercontent.com/79f6dc189db7eca6c92f1ba98c53771c96823a432db3fd1d6b865720f5a655c8/68747470733a2f2f7472617669732d63692e6f72672f6a6d6b696d2f6c61726176656c2d656e74727573742d6775692e7376673f6272616e63683d74657374696e67)](https://travis-ci.org/jmkim/laravel-entrust-gui)[![Latest Stable Version](https://camo.githubusercontent.com/d9e801243ef29c9327ae499502a6747855b3d67d3c838388dea8a580e66da490/68747470733a2f2f706f7365722e707567782e6f72672f6a6d6b696d2f6c61726176656c2d656e74727573742d6775692f762f737461626c65)](https://packagist.org/packages/jmkim/laravel-entrust-gui)[![Total Downloads](https://camo.githubusercontent.com/7216050ade44a9ee3cb005c21b3b4adea3469e9b8cfe342ec881d3300ab00129/68747470733a2f2f706f7365722e707567782e6f72672f6a6d6b696d2f6c61726176656c2d656e74727573742d6775692f646f776e6c6f616473)](https://packagist.org/packages/jmkim/laravel-entrust-gui)[![Latest Unstable Version](https://camo.githubusercontent.com/de5678339179f7ed1a8f91fa25b7b8950cb9b92c75d80b367dc4ef1d3e0b3599/68747470733a2f2f706f7365722e707567782e6f72672f6a6d6b696d2f6c61726176656c2d656e74727573742d6775692f762f756e737461626c65)](https://packagist.org/packages/jmkim/laravel-entrust-gui)[![License](https://camo.githubusercontent.com/92fb0a4d600d0f235203831df38c904e7e250474c1beff7d5aee967395944ac6/68747470733a2f2f706f7365722e707567782e6f72672f6a6d6b696d2f6c61726176656c2d656e74727573742d6775692f6c6963656e7365)](https://packagist.org/packages/jmkim/laravel-entrust-gui)

Entrust GUI is a Admin Interface that makes the administration of users, roles and permissions easier for [Shanmuga's Laravel Entrust](https://github.com/shanmuga3/laravel-entrust) package.

This package is currently not for handling authentication, authorisation or registration of users.

[![User Panel Preview](https://camo.githubusercontent.com/3825e50b90a90471fdd0ada88b107ba6f7bdbbf9a21edf16b85f78a842f1fb10/687474703a2f2f692e696d6775722e636f6d2f39524a33714f692e706e67)](https://camo.githubusercontent.com/3825e50b90a90471fdd0ada88b107ba6f7bdbbf9a21edf16b85f78a842f1fb10/687474703a2f2f692e696d6775722e636f6d2f39524a33714f692e706e67)

Disclaimer
----------

[](#disclaimer)

Entrust GUI was fully written by Mitch Stanley ([@acoustep](https://github.com/acoustep)). The original codebase is placed at .

This package is a port for [Shanmuga's Laravel Entrust](https://github.com/shanmuga3/laravel-entrust).

- **(Laravel 5, original but unmaintained)** [acoustep's Entrust GUI](https://github.com/acoustep/entrust-gui) for [Zizaco's ENTRUST](https://github.com/Zizaco/entrust)
- **(Laravel 5 ~ 9, ported and maintained)** [jmkim's Laravel Entrust GUI (this package)](https://github.com/jmkim/laravel-entrust-gui) for [Shanmuga's Laravel Entrust](https://github.com/shanmuga3/laravel-entrust)

You can easily migrate from acoustep's to this package by replacing:

- `Acoustep` to `Jmkim`
- `acoustep` to `jmkim`

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

[](#installation)

Add the package to your `composer.json` file

```
"jmkim/laravel-entrust-gui": "6.x-dev",
"shanmuga/laravel-entrust": "3.x-dev",
"watson/validating": "3.2.0 as 2.0.1"

```

Add the service provider to your `config/app.php` file

```
Jmkim\EntrustGui\EntrustGuiServiceProvider::class,

```

Add the Entrust Alias to your `config/app.php` file as well.

```
'Entrust'   => Shanmuga\LaravelEntrust\LaravelEntrustFacade::class,

```

Publish the configuration file(s)

```
php artisan vendor:publish --tag="config"

```

Add the `table` key with the value `users` to the `providers.users` array in `config/auth.php`.

```
    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
            'table' => 'users',
        ],
        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

```

If you haven't already set up Entrust then make the migration file and run the migration.

```
php artisan entrust:migration
php artisan migrate

```

If you see the following error:

```
 [Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table
   `users` add unique `users_email_unique`(`email`))

```

Add the following to your `app/Providers/AppServiceProvider.php`

```
use Illuminate\Support\Facades\Schema;
...
public function boot() {
    Schema::defaultStringLength(191);
}

```

If you then see this error

```
ReflectionException  : Method Shanmuga\LaravelEntrust\MakeMigrationCommand::handle() does not exist

```

This is an issue with `Entrust`, there is a temporary fix by going to `vendor-> shanmuga-> laravel-entrust-> src-> commands-> MakeMigrationCommand.php` and changing `fire()` to `handle()` and re-running thie migration. [See here for more details](https://github.com/Zizaco/entrust/issues/836). Once this is done, rerun the migration commands.

Finally, if you have this error

```
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `role_user` add constraint `role_user_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade on update cascade)

```

Go to the newly created migration file (`entrust_setup_tables`) and update the `user_id` foreign key constraint in `role_user` to use `bigInteger`.

```
Schema::create('role_user', function (Blueprint $table) {
            $table->bigInteger('user_id')->unsigned();
            $table->integer('role_id')->unsigned();

            $table->foreign('user_id')->references('id')->on('users')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('role_id')->references('id')->on('roles')
                ->onUpdate('cascade')->onDelete('cascade');

            $table->primary(['user_id', 'role_id']);
});

```

Rerun the entrust migration afterwards (You may need to clear your database, too).

Entrust GUI uses [esensi/model](https://github.com/esensi/model) which means you can set your validation rules in your models.

To generate `User`, `Role` and `Permission` models run the `entrust-gui:models` command.

```
php artisan entrust-gui:models

```

See the **manually creating models** section if you prefer to adjust your current model files.

By default, all three files are published into the `app_path()` directory. You can specify the files separately and the location

Add the Entrust GUI middleware to `app\Http\Kernal.php`. This middleware will allow users with the role `admin` (case sensitive) to access Entrust GUI and deny other users.

```
protected $routeMiddleware = [
  // ...
  'entrust-gui.admin' => \Jmkim\EntrustGui\Http\Middleware\AdminAuth::class,
];

```

Finally, there is currently an issue with Entrust which requires you to set the cache driver to array. This may change in the future. You can change this setting in your `.env` file.

```
CACHE_DRIVER=array

```

At this point you're all good to go. See Getting Started for how to use the package.

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

[](#getting-started)

### Using Laravel Authentication

[](#using-laravel-authentication)

Run the auth command if you haven't already set it up.

```
php artisan make:auth

```

### Accessing Entrust GUI

[](#accessing-entrust-gui)

By default all routes are prefixed with `/entrust-gui`.

- Users: `/entrust-gui/users`
- Roles: `/entrust-gui/roles`
- Permissions: `/entrust-gui/permissions`

You can change this prefix by editing `route-prefix` in `config/entrust-gui.php`.

```
'route-prefix' => 'admin'

```

Pointing your app to `/entrust-gui/users` will redirect you to `/auth/login` if you are not logged in as admin using the default `entrust-gui.admin` middleware.

If you have not set up Laravel authentication you will see a `NotFoundHttpException` exception. See the Laravel [Authentication](http://laravel.com/docs/5.1/authentication) documentation for setting up the Login system in Laravel 5.1.

### Middleware

[](#middleware)

By default Entrust GUI uses `entrust-gui.admin` for middleware. This allows logged in users with the `admin` role to access it.

You can change the middleware in `config/entrust-gui.php` in the `middleware` setting.

If you wish to test out the system without middleware then go to `config/entrust-gui.php`, remove `entrust-gui.admin` middleware and keep `web` which is required for flash messages to work correctly in Laravel 5.2.

```
'middleware' => 'web',

```

If you want to change the name of the role that has access to the `admin` middleware, update `middleware-role` in the configuration file.

```
"middleware-role" => 'sudo-admin',

```

### Layout

[](#layout)

To use your own layout override the `layout` key in `config/entrust-gui.php` with the template you wish to use.

```
"layout" => "app", // located in views/app.blade.php

```

Each template yields to `heading` and `content` so make sure your new layout has those sections.

```

  title

  @yield('heading')
  @include('entrust-gui::partials.notifications')
  @yield('content')

```

### Editing Templates

[](#editing-templates)

To edit the template files you first need to publish them

```
php artisan vendor:publish --tag="views"

```

All files are then stored in the `resources/views/vendor/entrust-gui` directory.

### Routes

[](#routes)

You may wish to link to pages in your own templates. EntrustGUI follows Laravel's `Route::resource` method with the exception of `show`.

```
route('entrust-gui::users.index')
route('entrust-gui::users.create')
route('entrust-gui::users.destroy', $id)
route('entrust-gui::users.update', $id)
route('entrust-gui::users.edit', $id)

```

### Events

[](#events)

The following event classes are available:

- `UserCreatedEvent`, `UserDeletedEvent`, `UserUpdatedEvent`.
- `RoleCreatedEvent`, `RoleDeletedEvent`, `RoleUpdatedEvent`.
- `PermissionCreatedEvent`, `PermissionDeletedEvent`, `PermissionUpdatedEvent`.

#### Example Event Listener

[](#example-event-listener)

```
