Download the PHP package genealabs/laravel-governor without Composer

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

Governor For Laravel

Build Status Coverage Status Latest StableVersion Total Downloads

Governor for Laravel

Manage authorization with granular role-based permissions in your Laravel apps.

screencast 2017-06-04 at 3 34 56 pm

Goal

Provide a simple method of managing ACL in a Laravel application built on the Laravel Authorization functionality. By leveraging Laravel's native Authorization functionality there is no additional learning or implementation curve. All you need to know is Laravel, and you will know how to use Governor for Laravel.

Requirements

Installation

The user with the lowest primary key will be set up as the SuperAdmin. If you're starting on a new project, be sure to add an initial user now. If you already have users, you can update the role-user entry to point to your intended user, if the first user is not the intended SuperAdmin. Now let's get the package installed.

Install via composer:

Implementation

  1. First we need to update the database by running the migrations and data seeders:

  2. If you have seeders of your own, run them now:

  3. Next, assign permissions (this requires you have users already populated):

  4. Now we need to make the assets available:

  5. Lastly, add the Governable trait to the User model of your app:

Upgrading

The following upgrade guides should help navigate updates with breaking changes.

From 0.11.5+ to 0.12 [Breaking]

The role_user pivot table has replaced the composite key with a primary key, as Laravel does not fully support composite keys. Run:

From 0.11 to 0.11.5 [Breaking]

The primary keys of the package's tables have been renamed. (This should have been a minor version change, instead of a patch, as this was a breaking change.) Run:

From 0.10 to 0.11 [Breaking]

The following traits have changed:

From 0.6 to Version 0.10 [Breaking]

To upgrade from version previous to 0.10.0, first run the migrations and seeders, then run the update seeder:

to 0.6 [Breaking]

  1. If you were extending GeneaLabs\LaravelGovernor\Policies\LaravelGovernorPolicy, change to extend GeneaLabs\LaravelGovernor\Policies\BasePolicy;
  2. Support for version of Laravel lower than 5.5 has been dropped.

Configuration

If you need to make any changes (see Example selection below for the default config file) to the default configuration, publish the configuration file:

and make any necessary changes. (We don't recommend publishing the config file if you don't need to make any changes.)

Views

If you would like to customize the views, publish them:

and edit them in resources\views\vendor\genealabs\laravel-governor.

Policies

Policies are now auto-detected and automatically added to the entities list. You will no longer need to manage Entities manually. New policies will be available for role assignment when editing roles. Check out the example policy in the Examples section below. See Laravel's documentation on how to create policies and check for them in code: https://laravel.com/docs/5.4/authorization#writing-policies

Your policies must extend LaravelGovernorPolicy in order to function with Governor. By default you do not need to include any of the methods, as they are implemented automatically and perform checks based on reflection. However, if you need to customize anything, you are free to override any of the before, create, edit, view, inspect, and remove methods.

Checking Authorization

To validate a user against a given policy, use one of the keywords that Governor validates against: before, create, edit, view, inspect, and remove. For example, if the desired policy to check has a class name of BlogPostPolicy, you would authorize your user with something like $user->can('create', (new BlogPost)) or $user->can('edit', $blogPost).

Filter Queries To Show Ownly Allowed Items

Often it is desirable to let the user see only the items that they have access to. This was previously difficult and tedious. Using Nova as an example, you can now limit the index view as follows:

The available query filters are:
- `filterDeletable(Builder $query)`
- `filterUpdatable(Builder $query)`
- `filterViewable(Builder $query)`
- `filterViewAnyable(Builder $query)`

The same functionality is availabe via model scopes, as well:
- `deletable()`
- `updatable()`
- `viewable()`
- `viewAnyable()`

Tables

Tables will automatically be updated with a governor_owned_by column that references the user that created the entry. There is no more need to run separate migrations or work around packages that have models without a created_by property.

Admin Views

The easiest way to integrate Governor for Laravel into your app is to add the menu items to the relevant section of your app's menu (make sure to restrict access appropriately using the Laravel Authorization methods). The following routes can be added:

For example:

403 Unauthorized

We recommend making a custom 403 error page to let the user know they don't have access. Otherwise the user will just see the default error message. See https://laravel.com/docs/5.4/errors#custom-http-error-pages for more details on how to set those up.

Authorization API

You can check a user's ability to perform certain actions via a public API. It is recommended to use Laravel Passport to maintain session state between your client and your backend. Here's an example that checks if the currently logged in user can create GeneaLabs\LaravelGovernor\Role model records:

This next example checks if the user can edit GeneaLabs\LaravelGovernor\Role model records:

The abilities inspect, edit, and remove, except create and view, require the primary key to be passed.

Role-Check API

// TODO: add documentation

Examples

Config File

Policy

No Methods Required For Default Policies

Adding policies is crazily simple! All the work has been refactored out so all you need to worry about now is creating a policy class, and that's it!

Default Methods In A Policy Class

Adding any of the before, create, update, view, viewAny, delete, restore, and forceDelete methods to your policy is only required if you want to customize a given method.


All versions of laravel-governor with dependencies

PHP Build Version
Package Version
Requires genealabs/laravel-casts Version dev-feature/upgrade-to-blade-components @dev
illuminate/support Version ^9.0|^10.0
illuminate/view Version ^9.0|^10.0
php Version ^7.3|^8.0
ramsey/uuid Version ^4.0
titasgailius/search-relations Version ^1.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 genealabs/laravel-governor contains the following files

Loading the files please wait ....