Download the PHP package xdroidteam/xtrust without Composer

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

Laravel permission, role based rights

MIT licensed

Contents

Key features

  1. You have roles and permissions. Permissions can be attached to a role, and roles can be attached to a single user, but also you can attach or detach permission/permissions from a specific user.
  2. Permissions and roles are stored in the cache, editing them automatically refreshes it. We use cache tags, so regular file or database cache drivers doesn't work, please use memcached instead.
  3. Inspired by Zizaco/entrust
  4. Please note, the package is under development, only tested with Laravel 5.2.

Installation

Add the following line to your composer.json (Laravel 5.4 and below):

"xdroidteam/xtrust": "0.1.*"

Add the following line to your composer.json (Laravel 5.5):

"xdroidteam/xtrust": "0.2.*"

Then run composer update.

or you can run the composer require command from your terminal:

composer require xdroidteam/xtrust

Then in your config/app.php add to the providers array (not needed after Laravel 5.5):

and to aliases array (not needed after Laravel 5.5):

If you are going to use Middleware (requires Laravel 5.1 or later) you also need to add

to routeMiddleware array in app/Http/Kernel.php.

Migration

Deploy migration file:

You may now run it with the artisan migrate command:

Models

Role

Create a Role model inside app/models/Role.php using the following example:

Permission

Create a Permission model inside app/models/Permission.php using the following example:

User

Next, use the XTrustUserTrait trait in your existing User model. For example:

Don't forget to dump composer autoload

Concept

There are roles and permissions. You can attach many permissions to a role, and attach many roles to a user, like in Zizaco/entrust. The main difference, that you can directly attach or detach permissions to a user.

For example

You have four permissions:

  1. can_show
  2. can_create
  3. can_edit
  4. can_delete

You have two roles, with permissions:

  1. admin:
    1. can_show
    2. can_create
    3. can_edit
    4. can_delete
  2. user:
    1. can_show

You have two users, with roles:

  1. Adam Admin:
    1. admin
  2. Super User
    1. user

If you don't want Adam Admin, to be able to delete, you can simply detach the can_delete permission from him. The admin group can still have the can_delete permission, but Adam will not. If you want Super User to be able to edit, you can attach this permisson (can_edit) to her. The other users in the user role will still be unable to edit, except her.

Because of this logic, you can't check the user roles, only the permissions!

Example for UI: Screenshot

Usage

Permission checking

Simple checking

Check one permission:

Returns true, if the authanticated user has the permission, returns false if not.

Check multiple permissions:

Returns true, if the authanticated user has all the permissions, returns false if not.

Or:

Returns true, if the authanticated user has one of the permissions, returns false if not.

You can also check within the user model:

Middleware

For multiple permission check use pipe symbol as OR operator:

To emulate AND functionality just use multiple instances of middleware For multiple permission check use pipe symbol as OR operator:

Blade

Multiple permissions:

Returns true, if the authanticated user has all the permissions, returns false if not.

Or:

Returns true, if the authanticated user has one of the permissions, returns false if not.

Role checking

Simple checking

Check one role:

Returns true, if the authanticated user has the role, returns false if not.

Check multiple roles:

Returns true, if the authanticated user has all the roles, returns false if not.

Or:

Returns true, if the authanticated user has one of the roles, returns false if not.

You can also check within the user model:

Attaching detaching

Always use the the id of the role or permission for attaching/detaching!

Attach to a user

Attach one role to a user:

Attach multiple roles to a user:

Attach one permission to a user:

Attach multiple permissions to a user:

Detach from a user

Detach one role from a user:

Detach multiple roles from a user:

Detach one permission from a user:

Detach multiple permissions from a user:

Attach to a role

Attach one permission to a role:

Attach multiple permissions to a role:

Detach from a role

Detach one permission from a role:

Detach multiple permissions from a role:


All versions of xtrust with dependencies

PHP Build Version
Package Version
Requires cviebrock/eloquent-sluggable Version ^9.0|^10.0
illuminate/auth Version ^9.0|^10.0
illuminate/support Version ^9.0|^10.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 xdroidteam/xtrust contains the following files

Loading the files please wait ....