Download the PHP package larapacks/authorization without Composer

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

Authorization

Build Status Scrutinizer Code Quality Total Downloads Latest Stable Version License

An easy, native role / permission management system for Laravel.

🚨 Repository Has Moved 🚨

This repository has been moved to: DirectoryTree/Authorization.

Index

Installation

Note: Laravel 5.5 or greater is required.

To get started, install Authorization via the Composer package manager:

composer require larapacks/authorization

The Authorization service provider registers its own database migration directory with the framework, so you should migrate your database after installing the package. The Authorization migrations will create the tables your application needs to store roles and permissions:

php artisan migrate

Now insert the Larapacks\Authorization\Traits\Authorizable onto your App\Models\User model:

You can now perform user authorization.

Migration Customization

If you would not like to use Authorization's default migrations, you should call the Authorization::ignoreMigrations method in the register method of your AppServiceProvider. You may export the default migrations using php artisan vendor:publish --tag=authorization-migrations.

Model Customization

By default, the App\Models\User class is registered as the authorizable user model.

You're free to extend the models used internally by Authorization, or create your own.

Instruct Authorization to use your own models via the Authorization class in your AuthServiceProvider:

Be sure to add the relevant traits for each of your custom models:

Role Model:

Permission Model:

Usage

Authorization utilizes native Laravel relationships, so there's no need to learn a new API.

Create a permission:

Grant the permission to a role:

Now assign the role to the user:

You can also create user specific permissions:

Checking Permissions & Roles

Using Laravel's native $user->can() method:

Using Laravel's native authorize() method in your controllers:

Using Laravel's native Gate facade:

Using Laravel's native @can directive in your views:

Checking Permissions & Roles (Using Authorization Package Methods)

Checking for permission:

Checking for multiple permissions:

Checking if the user has any permissions:

Checking if the user has a role:

Checking if the user has specified roles:

Checking if the user has any specified roles:

Caching

By default all permissions are cached to prevent them from being retrieved on every request.

This cache is automatically flushed when permissions are created, updated, or deleted.

If you would like to disable the cache, call Authorization::disablePermissionCache in your AuthServiceProvider:

Cache Key

By default, the permission cache key is authorization.permissions.

To alter the cache key, call Authorization::cacheKey in your AuthServiceProvider:

Cache Expiry

By default, the permission cache will expire daily.

To alter this expiry date, call Authorization::cacheExpiresIn in your AuthServiceProvider:

Gate Registration

By default all permissions you create are registered in Laravel's Gate.

If you would like to disable this, call Authorization::disableGateRegistration in your AuthServiceProvider:

Middleware

Authorization includes two useful middleware classes you can utilize for your routes.

Insert them into your app/Http/Kernel.php:

Once you've added them, you can start using them.

Note: When a user does not meet the requirements using the middleware, a 403 HTTP exception is thrown.

To guard a route to only allow specific permissions:

To guard a route to allow a specific role:

Running Tests

To run your applications tests, you must instantiate the PermissionRegistrar inside your TestCase::setUp() method before running your tests for permissions to register properly:

Upgrading v1 to v2

Configuration

Configuration is now done via static methods on the Authorization class.

You may delete the published config/authorization.php file.

Traits

The UserRolesTrait has been renamed to Authorizable.

The PermissionRolesTrait has been separated into multiple traits. You must apply the HasRoles, HasUsers, and ClearsCachedPermissions traits.

The RolePermissionsTrait has been renamed to ManagesPermissions.

Closure Permissions

Permission closures have been removed. If you still require this functionality, continue using v1.


All versions of authorization with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
illuminate/database Version ^5.5|^6.20|^7.0|^8.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 larapacks/authorization contains the following files

Loading the files please wait ....