Download the PHP package miracuthbert/laravel-roles without Composer

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

Laravel Roles

An Eloquent roles and permissions package for Laravel 5.8 and up.

Installation

To can install the package via composer:

Setup

The package takes advantage of Laravel Auto-Discovery, so it doesn't require you to manually add the ServiceProvider.

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

Migrations

You first need to publish the packages migrations:

For those who had published migrations earlier use command(s) below to publish updated changes:

Then run the migrate command:

Seeding

By default the package includes a seeder for roles and permissions, RolesAndPermissionsTableSeeder.

You can add it to your DatabaseSeeder or use the command below to run it in isolation.

See the usage section on how to assign a role to a user via the console.

Configuration

To customize the package usage, copy the package config to your local config by using the publish command:

The package includes configuration for:

Role Sharing

allow_shared_roles key enables the package to query for roles that can be shared by models.

Example, an admin role for Team model can be shared and easily managed by the app admin, compared to a manager role that may vary between teams.

User Model

The default user model is App\Models\User::class the default namespace of User model.

You can change the default user model by changing model key under users in the config file.

See the usage section on how to enable roles and permissions on the User model.

Middleware

Under middleware you can configure the abort_code, which by default is 403.

Permitable Types

You can setup the types of role and permissions allowed to be created within your app.

This can be useful in a multi-tenant app for filtering out Admin and Tenant based permissions and roles.

For example if your application has teams and each member performs unique tasks you can define a permission or role type team under permitables in the config file which can be used to filter out only team permissions or roles.

Permitable types for non admin roles need to be linked to added as a key in the models array in the config file.

Models

You can also map permitables types (mentioned above) to related models.

Each model can only be related to a single permitable type.

Usage

To start assigning roles and permissions to users, you must first add the LaravelRolesUserTrait trait to the User model.

The User model should match the one indicated in the package's config file. See configuration.

Assigning a Role

Basic

To assign a role to a user you can call the assignRole method on a User model instance.

The assignRole method accepts a role (Role model instance), expiresAt a date which is optional and giver an instance Eloquent Model among models registered in configuration which is optional.

The expiresAt value must be a future date.

giver value can omitted when role assigned belongs to a registered model

Via Console

To assign role via console use command below, passing in a registered User's email and a valid Role slug.

For example a user with email [email protected] and a Role named Admin Root with slug admin-root will be:

You can seed the roles and permissions table with the seeder that comes with the package. See Seeding.

Revoking a Role

Revoking a role is the same as assign, where the revokeRoleAt method is called on a User model instance.

The method accepts a role (Role model instance) and expiresAt a date which is optional.

If the expiresAt date is not given the role will be revoked immediately.

Revoking all Roles

To revoke all roles from a user, call the revokeRoles method on a User model instance.

The method accepts an optional array of roles (or a collection of Role model instances).

If no value is passed to method, the user's valid roles will be revoked.

Note: Revoking a role just set's the expired timestamp, not deleting the history of user's roles.

Detaching all Roles

To detach all roles from a user, call the detachRoles method on a User model instance.

The method accepts an optional array of roles (or a collection of Role model instances).

Detaching roles from a user with completely delete the history of user's roles.

Authorization

There are various ways you can authorize a user using the package:

Roles

To check a user has a valid role use the slug of a valid Role model.

The role must be usable (active).

Via User Model

Checking for multiple roles:

Or

Via Blade Helpers

Middleware

You can user the role middleware to check if user has access.

It accepts a role slug and permission slug or name.

In Routes
In Controller

See permissions section to learn how to authorize a user via permissions.

Permissions

To check a user has access via permission use a slug or name of a valid Permission model.

eg. a permission named browse admin can be passed as browse-admin or browse admin.

The permission must be usable (active).

An additional parameter giver is accepted, if you have to check for permissions based on the model that assigned it.

For example, to check a user has a permission through a role of type team:

Whether the id is a slug or a basic id, it will be resolved by the package.

When passing a type make sure it has a corresponding model registered under the package's config in the models key.

Via Gates

Via User model

Via Blade Helpers

Middleware

Using middleware there are two ways:

In Routes
In Controller

Security Vulnerabilities

If you discover a security vulnerability, please send an e-mail to Cuthbert Mirambo via [email protected]. All security vulnerabilities will be promptly addressed.

Credits

License

The project is open-sourced software licensed under the MIT license.


All versions of laravel-roles with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
illuminate/console Version >=6.0
illuminate/database Version >=6.0
illuminate/support Version >=6.0
kalnoy/nestedset 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 miracuthbert/laravel-roles contains the following files

Loading the files please wait ....