Laravel Roles and Permissions

Last update: Nov 1, 2021

Introduction to Laravel Roles and Permission App Starter Kit

Roles and sanctions are a paramount part of many web applications. In project, we have optically discern how we can implement utilizer roles and sanctions system in laravel. We will optically discern it from scratch. We won't utilize spatie/laravel-sanction package for doing it. But you can utilize spatie/laravel-sanction to engender this roles and sanctions system in laravel 8.

It is consequential to integrate laravel utilizer roles and sanctions mechanism in our immensely colossal scale application to give the sanction to utilizer to categorical task. We will visually perceive from scratch laravel 7/6 utilizer roles and sanctions tutorial.

About Laravel Roles and Permission App Starter Kit

This Application has been compiled to give laravel developers an easy way to setup a new project with roles and permissions done already for them. This Project has been created with Developers in mind. The App provides the following ease during development:

  • Simple, fast roles and permissions Addition.

Laravel is accessible, powerful, and provides tools required for large, robust applications.

Setting Up the project

To clone the project run:

git clone https://github.com/JuniaKE/role-permission.git

cd into your project

You will need to be inside that project file to enter all of the rest of the commands in this tutorial. So remember to type cd role-permission to move your terminal working location to the project file we just barely created.

Install Composer Dependencies

Whenever you clone a new Laravel project you must now install all of the project dependencies. This is what actually installs Laravel itself, among other necessary packages to get started.

When we run composer, it checks the composer.json file which is submitted to the github repo and lists all of the composer (PHP) packages that your repo requires. Because these packages are constantly changing, the source code is generally not submitted to github, but instead we let composer handle these updates. So to install all this source code we run composer with the following command.

composer install

Install NPM Dependencies

Just like how we must install composer packages to move forward, we must also install necessary NPM packages to move forward. This will install Vue.js, Bootstrap.css, Lodash, and Laravel Mix.

This is just like step 4, where we installed the composer PHP packages, but this is installing the Javascript (or Node) packages required. The list of packages that a repo requires is listed in the packages.json file which is submitted to the github repo. Just like in step 4, we do not commit the source code for these packages to version control (github) and instead we let NPM handle it.

npm install

or if you prefer yarn (as i do).

yarn install

Create a copy of your .env file

.env files are not generally committed to source control for security reasons. But there is a .env.example which is a template of the .env file that the project expects us to have. So we will make a copy of the .env.example file and create a .env file that we can start to fill out to do things like database configuration in the next few steps.

cp .env.example .env

This will create a copy of the .env.example file in your project and name the copy simply .env.

Generate an app encryption key

Laravel requires you to have an app encryption key which is generally randomly generated and stored in your .env file. The app will use this encryption key to encode various elements of your application from cookies to password hashes and more.

Laravel’s command line tools thankfully make it super easy to generate this. In the terminal we can run this command to generate that key. (Make sure that you have already installed Laravel via composer and created an .env file before doing this, of which we have done both).

php artisan key:generate

If you check the .env file again, you will see that it now has a long random string of characters in the APP_KEY field. We now have a valid app encryption key.

Create an empty database for our application

Create an empty database for your project using the database tools you prefer (My favorite is phpmyadmin for). In our example we created a database called roles-permissions. Just create an empty database here, the exact steps will depend on your system setup.

In the .env file, add database information to allow Laravel to connect to the database

We will want to allow Laravel to connect to the database that you just created in the previous step. To do this, we must add the connection credentials in the .env file and Laravel will handle the connection from there.

In the .env file fill in the DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD options to match the credentials of the database you just created. This will allow us to run migrations and seed the database in the next step.

Migrate the database

Once your credentials are in the .env file, now you can migrate your database.

php artisan migrate

It’s not a bad idea to check your database to make sure everything migrated the way you expected.

Seed the database

If your repository has a seeding file setup, then now is the time to run the seed, which fills your database with starter or dummy data. If the repo doesn’t mention the existence of a seeder file, then skip this step.

After the migrations are complete and you have the database structure required, then you can seed the database (which means add dummy data to it).

php artisan db:seed

Social Login

We have added social logins to our app. To use the Social Login, modify config/services.php with the correct redirect as well as client_id and client_secret for every app you are to use for Oauth.

Wrapping Up

That is all you need to get started on a project.

Hopefully this has helped you get up and running with your next project. Be sure to follow me here on JuniaKE or on the Twitter Page @juniakeofficial.

GitHub

https://github.com/JuniaKE/role-permission
You might also like...

Proyecto para aprender a utilizar privilegios (roles y permisos) con CRUDBooster

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

May 9, 2022

Role-based Permissions for Laravel 5

ENTRUST (Laravel 5 Package) Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 5. If you are looking for the Laravel 4 ve

Jun 22, 2022

Light-weight role-based permissions system for Laravel 6+ built in Auth system.

Kodeine/Laravel-ACL Laravel ACL adds role based permissions to built in Auth System of Laravel 8.0+. ACL middleware protects routes and even crud cont

Jun 17, 2022

PermissionsMakr is a Laravel package that will help any developer to easily manage the system's users permissions

PermissionsMakr is a Laravel package that will help any developer to easily manage the system's users permissions

Nov 30, 2021

Manage authorization with granular role-based permissions in your Laravel Apps.

Manage authorization with granular role-based permissions in your Laravel Apps.

Governor For Laravel Manage authorization with granular role-based permissions in your Laravel apps. Goal Provide a simple method of managing ACL in a

May 30, 2022

Laravel mongodb permissions

Laravel mongodb permissions

May 10, 2022

A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package

laravel-social A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package. I

Apr 13, 2022

An OAuth 2.0 bridge for Laravel and Lumen [DEPRECATED FOR LARAVEL 5.3+]

An OAuth 2.0 bridge for Laravel and Lumen [DEPRECATED FOR LARAVEL 5.3+]

OAuth 2.0 Server for Laravel (deprecated for Laravel 5.3+) Note: This package is no longer maintaned for Laravel 5.3+ since Laravel now features the P

Jun 24, 2022

It's a Laravel 8 authentication markdown that will help you to understand and grasp all the underlying functionality for Session and API Authentication

About Auth Starter It's a Laravel 8 authentication markdown that will help you to understand and grasp all the underlying functionality for Session an

Jun 9, 2022
Handle roles and permissions in your Laravel application

Laratrust (Laravel Package) Version Compatibility Laravel Laratrust 8.x 6.x 7.x 6.x 6.x 6.x 5.6.x - 5.8.x 5.2 5.3.x - 5.5.x 5.1 5.0.x - 5.2.x 4.0. Ins

Jun 25, 2022
Powerful package for handling roles and permissions in Laravel 5

Roles And Permissions For Laravel 5 Powerful package for handling roles and permissions in Laravel 5 (5.1 and also 5.0). Installation Composer Service

Jun 17, 2022
Laravel Roles and Permissions

Introduction to Laravel Roles and Permission App Starter Kit Roles and sanctions are a paramount part of many web applications. In project, we have op

Nov 1, 2021
A Powerful package for handling roles and permissions in Laravel with GUI.
A Powerful package for handling roles and permissions in Laravel with GUI.

Laravel Roles A Powerful package for handling roles and permissions in Laravel. Supports Laravel 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6.0, 7.0, and 8.0+. Tab

Jun 27, 2022
This is a lightweight package that allows you assign roles and permissions to any Laravel model, or on a pivot table (many to many relationship).
This is a lightweight package that allows you assign roles and permissions to any Laravel model, or on a pivot table (many to many relationship).

Simple Laravel roles and permissions Introduction This package allows you to assign roles and permissions to any laravel model, or on a pivot table (m

May 25, 2022
Roles & Permissions for Laravel 8 / 7 / 6 / 5

Defender Defender is an Access Control List (ACL) Solution for Laravel 5 / 6 / 7 (single auth). (Not compatible with multi-auth) With security and usa

Apr 28, 2022
Laravel Users (Roles & Permissions, Devices, Password Hashing, Password History).
Laravel Users (Roles & Permissions, Devices, Password Hashing, Password History).

LARAVEL USERS Roles & Permissions Devices Password Hashing Password History Documentation You can find the detailed documentation here in Laravel User

Apr 20, 2022
Associate users with roles and permissions
Associate users with roles and permissions

Associate users with permissions and roles Sponsor If you want to quickly add authentication and authorization to Laravel projects, feel free to check

Jul 3, 2022
Eloquent roles and abilities.
Eloquent roles and abilities.

Bouncer Bouncer is an elegant, framework-agnostic approach to managing roles and abilities for any app using Eloquent models. Table of Contents Click

Jun 26, 2022
This package helps you to associate users with permissions and permission groups with laravel framework
This package helps you to associate users with permissions and permission groups with laravel framework

Laravel ACL This package allows you to manage user permissions and groups in a database, and is compatible with Laravel v5.8 or higher. Please check t

Jun 28, 2022