Download the PHP package isakzhanov-r/laravel-permissions without Composer

On this page you can find all versions of the php package isakzhanov-r/laravel-permissions. 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-permissions

Laravel Permissions

Basic roles and permissions is a succinct and flexible way to add Role-based Permissions

Total Downloads Latest Stable Version Latest Unstable Version

Contents

Installation

To get the latest version of Laravel Permissions package, simply require the project using Composer:

Instead, you can, of course, manually update the dependency block require in composer.json and run composer update if you want to:

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php:

Copy the package config to your local config with the publish command:

You can create the DB tables by running the migrations:

This command will create such roles, permissions, user_roles and permissible tables.

But you can also use the command for automatic installation

This command will publish the configuration file. Run the migration command, generate models for tables, and change the User model . all configuration of the package will happen automatically. after executing this command, you don't need to configure anything.

Configuration

To further customize table names and model namespaces, edit the config/laravel_permissions.php after you run command

before you run the command php artisan migrate four new tables will be present:

Models

Role model

The Role model has three main attributes:

Base model IsakzhanovR\Permissions\Models\Role use trait HasPermissions

Permission model

The Permission model has the same three attributes as the Role:

if you look at the default model IsakzhanovR\Permissions\Models\Permission, you will see morphedByMany relationships for users and roles. You can extend this list with your own entities.

Example :

And PostType model must use trait HasPermissions

Permissible model

This is the standard polymorph pivot model The Permissible model has the same three attributes:

You also need to create a model Permissible and inherit from IsakzhanovR\Permissions\Models\Permissible

After creating model you also need to append link in config file

Or use the command to automatically install the package and generate models and a configuration file

Usage

Creating

Let's start by creating the following Roles and Permissions:

Now we just need to creat permissions: We will create permissions without a description, and slug is created from title

User model

First, use the IsakzhanovR\Permissions\Traits\HasPermissions and IsakzhanovR\Permissions\Traits\HasRoles traits to your User model.

If you use the command php artisan laravel-permissions:migrate, these changes will occur automatically and your User model will look like this:

Attach, detach and sync permissions

This package allows users to be associated with permissions and roles. Each role is associated with several permissions. in this case, the User can have a separate Permission that is not included in the list of permissions for the role. Role and Permission are the usual Eloquent models.

Attach permissions

So, when the roles are created let's assign them to the users. Thanks to the HasRoles trait this is as easy as:

The method $user->attachRole() accepts an argument that can be an id, slug, or instance of Role the model

Let's start adding permissions to roles and users:

So we added permissions for the admin and manager roles and also gave personal permissions for the user.

All entities that use trait HasPermission have access to permission relationships and the following methods for adding permissions:

Detach permissions

To revoke roles and permissions, use the following methods:

Syncing permissions

To synchronization roles and permissions, use the following methods:

Checking for permissions

Now we can check for roles and permissions simply by doing:

You can have as many roles as you want for each user, and Vice versa.

We can check permissions for entities using the following method:

You can also use placeholders (wildcards) to check any matching permission by doing:

Middleware

You can use a middleware to filter routes and route groups by permission or role. Add middlewares in $routeMiddleware of app/Http/Kernel.php file:

You can use a middleware to filter routes and route groups by permission or role

If you need to check whether there are matches in permissions use ability

Artisan commands

You can create a role or a permission from a console with artisan commands:

You can also invoke the creation of roles and permissions from your application:

Artisan::call('laravel-permissions:create-role', ['name' => $name]); Artisan::call('laravel-permissions:create-permission', ['name' => $name]);

License

This package was written under Andrey Helldar supervision under the MIT License.


All versions of laravel-permissions with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1.3|^8.0
illuminate/auth Version ^5.5|^6.0|^7.0|^8.0
illuminate/cache Version ^5.5|^6.0|^7.0|^8.0
illuminate/console Version ^5.5|^6.0|^7.0|^8.0
illuminate/database Version ^5.5|^6.0|^7.0|^8.0
illuminate/http Version ^5.5|^6.0|^7.0|^8.0
illuminate/support Version ^5.5|^6.0|^7.0|^8.0
symfony/http-kernel Version ^3.3|^4.0|^5.0
symfony/finder Version ^5.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 isakzhanov-r/laravel-permissions contains the following files

Loading the files please wait ....