Download the PHP package nahid/permit without Composer

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

Laravel Permit

Laravel Permit is an authorization and ACL package for laravel. Its fast and more customizable. You can easily handle role based ACL or specific user wise permission. So, Lets start a journey with Laravel Permit.

Installation

You can start it from composer. Go to your terminal and run this command from your project root directory.

Wait for a while, its download all dependencies.

Configurations

After complete installation then you have to configure it. First copy these line paste it in config/app.php where providers array are exists.

and add the line for facade support

hmm, Now you have to run this command to publish necessary files.

and then go to config/permit.php and edit with your desire credentials.

Now run this command for migrations

You are all most done, just add this trait Nahid\Permit\Users\Permitable in your User model. Example

Yeh, its done.

How does it work?

Its a common question. But first you have to learn about our database architecture. When you run migrate command then we create a table 'permissions' with field 'role_name' and 'permission', and add two column 'role' and 'permissions' in users table. role column store users role and permissions column store user specific controls. Here role column has a relation with permissions.role_name column with its controls. permissions.permission handle role based control.

We store permissions as JSON format with specific modules and abilities.

Here user and post is a service/module name and create, update and delete or others are abilities.

Set User Role

Syntax

bool Permit::setUserRole(int $user_id, string $role_name)

Example

Set User Permission

Syntax

bool Permit::setUserPermissions(int $user_id, string $module, array $abilities)

Example

Set Role Permission

Syntax

bool Permit::setRolePermissions(string $role_name, string $module, array $abilities)

Example

How to Authorize an event?

Check user ability

In post.create is an event with module/service. Here post is a module and create is an ability.

So if the user is authorized with post create event then the user will be passed.

Permit::userCan() method return boolean. If you want to throw Unauthorized exception you may use

Permit::userAllows() with same parameters.

Check user role ability

Here when given users role allowed this event then its passed. Here is a similar method for throw exception

Permit::roleAllows()

Check Users all ability

You can check user ability from user or user role. Here we check both(user and role) permissions but if user specific permission was set then its priority will be first.

and here is a alternate method for throw exception

Permit::allows()

Policy

Policy is a feature like laravel native authorization but its quite easy. Permit allows you to manage ACL and Authorization in a same line. I know your first question is where we use Policy?

Lets see an example, suppose you have a user commenting system where every user comment under a blog post and comment owner can edit and deletes their comments. So you have to apply an authorization system where user can modify his/her own comment. So here we have to implement our custom policy. Take a look

Make a policy

First we have to create a class for policy.

and now map this policy with our config file. Go to config/permit.php and update this section in `policies

Now you have bind this policy with an ability. Suppose we have a module about comment. so this ability will look like in config/permit.php abilities section

here 'update'=>'comment.update' update is an ability and comment.update is a policy. This system are bind policy with ability. so now you can use this policy like a general ability.

You can predefined your all roles permissions in config file. First set your aprox abilities and then assign abilities to roles. Take a look

Here admin and user are role and its value is permissions or abilities. But you can't use this because its not synced with database. so run this command from your terminal

How to use policy based ability

In previous section we are bind comment.update policy with an ability and thats are same name. Lets check currently opened comment is authorized for logged in user.

here first parameter is authorized user, second one is permission and third one is policy method's parameter. we are always automatically bind authenticated user as a first parameter and then others parameter will pass.

You can use others method like roleCan, 'userCan', all helper functions and blade directives as same procedure.

Sometimes you have to check if the given user able to perform for any ability. so we make it easy. lets see

But if your ability was bind with a policy and its required paramters, then you can pass abilities with associative array.

Here if the given user is assigned to any one abilities then its allows.

Commands

We provide several command for make user experience better

php artisan permit:sync

Sync with your composed permissions with database.

php artisan permit:set

Add permission to an user or role

php artisan permit:remove

Remove permissions from an user or role

php artisan permit:fetch

Get permissions of an user or a role

php artisan permit:role

Create a new role

Helper functions

Here you can use helper function instead of facades.

user_can()

You can use user_can() instead of Permit::userCan()

user_allows()

You can use user_allows() instead of Permit::userAllows()

role_can()

You can use role_can() instead of Permit::roleCan()

role_allows()

You can use role_allows() instead of Permit::roleAllows()

canDo()

You can use canDo() instead of Permit::can()

allows()

You can use allows() instead of `Permit::allows()

Blade Directives

Sometimes you may want to use this functionalities in you view. Permit comes with all blade directives.

Example

You can also use else directive

List of directives

If you have any kind of query, please feel free to share with me

Thank you


All versions of permit with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.9
nahid/jsonq Version ^5.2
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 nahid/permit contains the following files

Loading the files please wait ....