Download the PHP package httpoz/roles without Composer

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

Roles for Laravel

Simple package for handling roles in Laravel.

Build Status Total Downloads codecov Latest Stable Version

Installation

This package is very easy to set up. There are only a couple of steps.

Previous Versions

For Previous versions please see the releases page

Composer

Add the package to your project via composer.

Config File And Migrations

To publish the package config's file and migrations to your application. Run this command inside your terminal.

Enable HasRole Trait And Contract

Include HasRole trait and also implement HasRole contract inside your User model.

And that's it!

Usage

Creating Roles

Because of Slugable trait, if you make a mistake and for example leave a space in slug parameter, it'll be replaced with a dot automatically, because of str_slug function.

Attaching And Detaching Roles

It's really simple. You fetch a user from database and call attachRole method. There is BelongsToMany relationship between User and Role model.

Syncing Roles

You may also use the sync method to attach roles to a user model. Any roles that are not passed into the method will be detached from the user's roles. So, after this operation is complete, only the roles passed into the method will be attached to the user:

Checking For Roles

You can now check if the user has required role.

And of course, there is a way to check for multiple roles:

In this case, a user has to have at least one of the given roles. Multiple options have been illustrated below that achieve the same goal.

In this case, a user has to have all the given roles. Multiple options have been illustrated below that achieve the same goal.

Find users by role

There are multiple ways to get a list of users by their given role.

Using the role's id

Using the role's slug

Using the role's group

If you use soft delete on your Users model, and want to include deleted users, you can use usersWithTrashed method instead of users.

Groups

If a user has multiple roles, method group returns the first one in alphabetical order (a better implementation of this will be explored).

Group is intended to collectively organise and assign permissions (Laravel's built-in authorization feature) to a role group that can be shared by multiple roles (examples and implementation to be added to documentation in future).

Blade Extensions

There are two Blade extensions. Basically, it is replacement for classic if statements.

Middleware

This package comes with VerifyRole and VerifyGroup middleware. You must add them inside your app/Http/Kernel.php file.

Now you can easily protect your routes.

It throws \HttpOz\Roles\Exceptions\RoleDeniedException or \HttpOz\Roles\Exceptions\GroupDeniedException exceptions if it goes wrong.

You can catch these exceptions inside app/Exceptions/Handler.php file and do whatever you want. You can control the error page that your application users see when they try to open a page their role is not allowed to. This package already has a view bundled with it that should have been published to resources/views/vendor/roles/error.blade.php when you published the package. Simply add the below condition inside your app\Exceptions\Handler.php's render function. Feel free to point to another view of your choice.

Config File

You can change connection for models, slug separator, models path and there is also a handy pretend feature. Have a look at config file for more information.

Caching

The configuration for cache expiry is defaulted to 2 weeks (in seconds). You can update this value to suit your project specific needs.

License

This package is free software distributed under the terms of the MIT license.


All versions of roles with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/cache Version ^9.0
illuminate/support Version ^9.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 httpoz/roles contains the following files

Loading the files please wait ....