Download the PHP package kerigard/laravel-roles without Composer

On this page you can find all versions of the php package kerigard/laravel-roles. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-roles

Laravel Roles

Build Status Total Downloads Latest Stable Version License

Permissions and roles for Laravel 9.20 and up.

Installation

Install package via composer:

Publish the configuration and migration files using the vendor:publish artisan command:

Customize the roles.php configuration file according to your requirements. After that run the migrations:

Usage

Connecting traits

To start using permission and role checking, your User model must use the Kerigard\LaravelRoles\Traits\HasRoles and Kerigard\LaravelRoles\Traits\HasPermissions traits:

It is not necessary to connect both traits at the same time.

Creating roles and permissions

Create roles and permissions, after which create a relationship between them:

You can override models through a config file.

Connect a role or permission to a user:

You can disable a role or permission for a user:

Or just sync the specified roles or permissions. Any roles or permissions that are not listed will be disabled:

Use this method if you don't want old roles or permissions to be disabled when syncing:

Permissions check

To check for permission, run:

All permissions are registered with Laravel Gates, so you can use the can function:

In a controller, you can use the authorize function to throw an exception if the user doesn't have permissions:

Roles check

To check if a role exists, run:

If you want to check the role in the controller and raise an exception if it is missing, then you need to replace the trait import in the app\Http\Controllers\Controller.php file:

After that, you can use the authorizeRole function in all controllers to check the role:

Blade directives

You can use directives in blade files to write conditions conveniently:

Middlewares

In the app/Http/Kernel.php file, you can specify a middleware for checking roles and permissions:

Then you can secure your routes:

Custom statuses

When throwing exceptions by default, Laravel returns a 403 error code with the message This action is unauthorized. You can specify your own error codes and messages for each role and permission:

Super admin

In the configuration, you can enable the super admin role. For users with this role, all permissions and role checks will be true.

Changelog

Please see the CHANGELOG for more information on what has changed recently.

License

MIT. Please see the LICENSE FILE for more information.


All versions of laravel-roles with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0.2|^8.1
laravel/framework Version ^9.20|^10.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kerigard/laravel-roles contains the following files

Loading the files please wait ....