Download the PHP package zaichaopan/access-granted without Composer

On this page you can find all versions of the php package zaichaopan/access-granted. 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 access-granted

Access Granted

This package allows you to add roles to users, add permissions to users and add permissions to role in your laravel app. It can be used in laravel 5.5 or higher.

Installation

Usage

Migration

After install the package, run the migration command to migrate roles, permissions, role_user, permission_user, and __permission_role__ tables.

The schema of the these tables

Assign Role to user

To assign role to user, add HasRoles trait the User model

This trait provides the follow methods

It can be used to give a roles or multiple roles to a user. For example:

Note:

If the user is given a role that he or she already has, the role won't be add again. And if the user is given a role that does not exist in the roles table, the invalid role won't be added.

It can be used to update user role. After calling this method on a user, he or she will only have the new roles. All the old roles will be removed.

Note:

If the updated role cannot be found, the it will be ignore and the user still keeps his o her old roles.

It can be used to remove a role or multiple roles from user. For example:

Note:

If the removed role cannot be found or the user doesn't have it, it will be ignored.

It is used to remove all roles from the user. For example:

It can be used to determine if a user has a role or any role from a list of roles. For example:

Assign Permission to Role

This package provides HasPermissions trait which is used by Role model by default. So you can give permissions to a role, you can use the following methods provided by the trait.

It can be used to give a permission or multiple permissions to a role, for example:

If the given permission is valid or is already give, it will be ignored.

It can be used to update the permissions of a role. After calling this method on a role, only the new permissions remain and all the old permissions it has will be removed. If an invalid permission is provided, it will be ignore. If all the provided permissions are invalid, the method returns false and role will still keep its old permissions. For example:

It can be used to withdraw a permission or multiple permissions from a role. If a withdrew permission is invalid, it will be ignored. If all the withdrew roles are invalid, the method returns false and the role will still keep its old permissions

It can be used to withdraw all the permission from the role.

It can be used to determine if a role has a specific permission. For example:

Add Permissions to User

To add permissions to user, you just need to add HasPermissions trait to your user model.

Now you can use all the methods discussed above in add permissions to role section to give permissions.

Has Permission through Role

When we uses both HasRoles and HasPermissions trait in the User model, to determine if a user has a specific permission, we have to check if he or she has the permission through permissions table or if his or her role has this permission.

To make things easier, this package provides another trait HasPermissionThroughRole. To use it, just add it to your User model

This trait provides a method hasPermissionThroughRole which can be used to determine if a user has a role that contains this permission. For example:

Note:

If we call hasPermission method, it can only check if the user has the permission through the permissions table. To avoid confusion, we can alias this method when using hasPermissions trait and override the hasPermission method to include check user's role permissions.

Middleware

This package provides two middleware: RoleMiddleware and PermissionMiddleware. They can be used to protect any route that needs a specific role and permission to access.

To use them, register them in your Kernel.php

To use them:

Blade Directive

This package provides blade directive which can be used in your blade to protect content that only use with a given role can access.

To only allow user with given permission to access some content. Using


All versions of access-granted with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
illuminate/support Version ~5.5.0|~5.6.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 zaichaopan/access-granted contains the following files

Loading the files please wait ...