Download the PHP package smallneat/trust without Composer

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

Trust Roles and Permissions

User roles and permissions for Laravel 4 via traits

Based on simplified ideas from https://github.com/Zizaco/entrust

Required setup

In the require key of composer.json file add the following

"smallneat/trust": "1.*"

Run the Composer update command

$ composer update

In your config/app.php add 'Smallneat\Trust\TrustServiceProvider' to the end of the $providers array

Configuration

Trust creates a number of tables and makes assumptions about the names of your models. You can configure all these settings using Laravel's normal config. First you'll need to publish the config from this package into your app config (you only need to bother with this the default names clash with existing tables in your application)

$ php artisan config:publish smallneat/trust

The default settings assume your models are called User, Role and Permission, and that the tables used to track these are called users, roles, permissions. Trust also uses 2 pivot tables to provide the many to many association between users, roles and permissions, which are called user_role and role_permission.

Once you've step up your config (or left it to the defaults), it's time for the next step.

Creating a DB migration

Now we need to create a Database migration using the following artisan command

$ php artisan trust:migration

It will generate the <timestamp>_setup_roles_permissions_tables.php migration in your app/database/migrations folder. You may now run the migration with the artisan migrate command:

$ php artisan migrate

After the migration, four new tables will be present, as described above.

NOTE: This does not create the users table for you. If you don't already have a users table you will need to add a migration to create one. We assume this table is called users and has a field user_id.

Using Trust in your models

Here we assume you already have a user model (like the one Laravel creates for you when you build a new Laravel app), and that it has a matching table in the database (normally called users).

Add the UserRoleTrait trait to the User model class (normally in app/models/User.php), like so...

Next, Create a Role model that looks a little like this...

The Role model has a name attribute, which is the name of the role (eg, 'Admin', 'Editor', 'Manager', 'User'). You can also find the users and permissions linked to the role using roles() and permissions().

Next, create a Permission model like this...

The Permission model has a name attribute, which is the name of the permission (for example, 'CreatePost', 'EditPost', 'DeletePost'), as well as a description attribute that is used to hold a readable description of the permission (eg, for presenting in your admin area). The roles() function will give you access to all the roles with this permission.

Finally, Don't forget to dump composer autoload

$ composer dump-autoload

Usage

Each user can be associated with as many roles as you like. Each role can grant as many permissions as you like and the permissions can be used to control access to various areas of your site.

Roles and Permissions are often created using your DB Seeds, but we will show some examples of creating a range of permissions and roles and assigning them them a user. Finally, we'll show how you can query the user to find out what they can and can't do...

First, we'll create some permissions for a fictional blog. These represent areas of your site that you want to protect in some way.

Next we'll create some different roles and associate some Permissions with them

Finally, we can give a user some of these roles and query them

License

Trust is free software distributed under the terms of the MIT license

Additional information

Any issues, please report here


All versions of trust with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.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 smallneat/trust contains the following files

Loading the files please wait ....