GithubHelp home page GithubHelp logo

deltaspectro / mesan-laravel-entrust-user-roles-permission Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mosesesan/mesan-laravel-entrust-user-roles-permission

0.0 2.0 0.0 22.63 MB

A PHP Administration Module with an ACL(Access Control List) based on Roles and Permissions, developed using the Laravel 5.4 framework and Entrust package.

Home Page: https://medium.com/@mosesesan/tutorial-6-how-to-build-a-laravel-5-4-4ba44f26b853

PHP 64.93% JavaScript 0.78% Vue 0.38% HTML 33.91%

mesan-laravel-entrust-user-roles-permission's Introduction

Laravel 5.4 Administration Module with Role-based permissions using Entrust package

A PHP Administration Module with an ACL(Access Control List) based on Roles and Permissions, developed using the Laravel 5.4 framework and Entrust package.

Testing

In your browser, navigate to

http://mosesesan.com/demos/entrust-admin-module/

You should be presented with Laravel welcome page, click login at the top right then login in using the admin credentials below.

email: [email protected]
password: adminpwd

After logging in, you will be redirected to the home page, at the top right, click the roles link to go to the roles page.

Roles Management

Click the “New Role” button to add a new role and assign the relevant permissions.

New Role

After adding the new role, click the “Show” button to view the role information

Role Info

Create a new role and test the edit and delete operations.

Now, lets add a new user and assign a role to them. Click the users link to go to the users page.

Click the “New User” button to add a new user and assign them the Senior Consultant role. Make sure you remember the password you set for the new user.

New User Users Management

After successfully creating the new user, test the “Show” and “Edit” operations.

Create a new user and test delete operation.

For the final test, log out and log back in using the credentials of our newly created user.

Once you log in, you should notice that the Roles and Users link is missing in the navigation bar on the top right of the page, this is because the user is not an Admin user

Logged In



If you attempt to access to the roles or users page using the url:

http://mosesesan.com/demos/entrust-admin-module/admin/roles

http://mosesesan.com/demos/entrust-admin-module/admin/users

You should be presented with our 403 page

Permission Error

Tutorial

Step 1: Create new project and install Entrust

Create Laravel project

laravel new administration-module

Open composer.json and update the require object to include entrust

"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",

"zizaco/entrust": "5.2.x-dev"
}

Then, run

composer update 

Step 2: Add Entrust Provider and Facades

Open up config/app.php, find the providers array and add the entrust provider:

Zizaco\Entrust\EntrustServiceProvider::class,

Find the aliases array and add the entrust facades:

'Entrust'   => Zizaco\Entrust\EntrustFacade::class,

Run the command below from the command line to publish the package config file.

php artisan vendor:publish

After you run this command you will see a new file in the config directory called entrust.php.

Entrust package provides it’s in-built middleware that way we can use it, open app/Http/Kernel.php and add the middleware.

protected $routeMiddleware = [
...
'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,
];

Now that the installation is done, lets move on to creating our database tables.

Step 3: Set Up Database

For this project we will be creating the following tables:

  1. roles — stores role records
  2. permissions — stores permission records
  3. role_user — stores many-to-many relations between roles and users
  4. permission_role — stores many-to-many relations between roles and permissions
  5. users
  6. clients
  7. jobs
  8. candidates

This first 4 tables are part of the Entrust package and are created with the entrust migration file which can be generated by running the command below.

php artisan entrust:migration

This command generates the entrust migration file (_entrust_setup_tables.php) in the database/migrations directory.

The full tutorial is available on my blog.

mesan-laravel-entrust-user-roles-permission's People

Contributors

mosesesan avatar

Watchers

James Cloos avatar Rene Torres Hernandez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.