Download the PHP package soumen-dey/laravel-role without Composer

On this page you can find all versions of the php package soumen-dey/laravel-role. 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-role

laravel-role

A lightweight Access Control package for Laravel 5.6 and above.

This package allows you to manage roles for your users, its very lightweight and require no extra dependencies.

Installation

Via Composer

For Laravel 5.5 and above the service provider will automatically get registered. Still if it is not registered, just add the service provider in config/app.php file.

Migrations

The migrations for this package will automatically run when you run the command.

Note: Make sure that you have your associated model table already migrated before using the command for this package.

Configurations

You need to publish the config file with:

This will publish file under the directory.

You can use this package without modifying the default configurations. The defaults are set to work with the Laravel's default model for auth which is the model. However you can change the configurations based on your need.

The configurations are:

Note: If you change the default model, make sure to change the model's table name and the pivot table name.

Tip: If you assign a null value to the pivot table name, this package will automatically generate the pivot table name for you.

Usage

Setup

Add the to your model or any other model that you want to associate roles with. That's it! You are all set to go!

Creating Roles

You can create new roles:

You can pass an array of role names or several role names at once.

Retrieving Roles

You can retrieve the roles by one of these methods:

Retrieve a role by its

Retrieve a role by its

All these methods will throw a exception if a role is not found, to change this behavior pass a second optional argument as , in such case the method will return if a role is not found.

A role can also be created if not found:

Check if a role exists:

If a role exists, this method will return the instance else it will return .

Assigning Roles to the model

Roles can be easily assigned by using one of these methods:

You can also assign roles by their or their model instances:

You can also pass an array:

There is also an method that does the same thing.

Revoking roles from the model

Roles can be revoked or removed from the model by one of these methods:

By their

By their :

By the instance:

This package is very flexible, in an extreme scenario you can also do this and still it won't complain :) :

There is also a method that does the same thing.

Sync Roles

Roles can be removed at once by the above methods, but roles can be removed and assigned at the same time:

You can also pass an array of either role , or instance.

Role associations with the model

The trait adds Eloquent Relationship to the associated model, so you can do this:

Names of the associated roles can be fetched:

The trait also adds a role scope to your models to scope the query to certain roles:

It can be also used as:

Determining Role associations

Check if the model has any of the specified roles (OR):

Using the role :

Using the role :

Using the instance:

You can also do this:

There is another method available:

The only difference between and is that you can pass as many arguments as you like to the method.

Note that both these methods returns a .

Check if the model has all the specified roles (AND):

This method returns only if all the specified roles are associated with the model, else it returns .

The method

This method is a quick way of determining if a model has a certain role. It is a very simple method and is faster than the above methods (the performance difference is very small, almost negligible).

This method only accept one argument which is the of the role.

Using the Middleware

This package comes with middleware. You can add it inside your file.

You can protect your routes using the middleware:

You can also use the middleware in a single route:

You can specify multiple roles in the middleware by separating them with a comma:

Note: The above method will determine if the model has any one (OR) of the specified roles.

To determine if a model has all (AND) of the specified roles, use the flag:

Note: The flag should be right after the middleware name, which in this case is . Thus the string should look like:

Using Blade Directive

By default, this package does not ship with any custom blade directive but you can add one easily. Assuming the default associated model is the model, just follow the steps:

In your add the following inside the method:

You can now use the directive:

For a more role specific directive:

You can now use the directive:

Or if you don't want any custom directive, you can do:

Change log

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

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email me at [email protected].

Credits

License

This package is released under the MIT License (MIT). Please see the license file for more information.


All versions of laravel-role with dependencies

PHP Build Version
Package Version
No informations.
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 soumen-dey/laravel-role contains the following files

Loading the files please wait ....