PHPackages                             toddish/verify - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. toddish/verify

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

toddish/verify
==============

A simple authentication bundle for Laravel 4/5. It features roles, permissions, password salting and is fully extendable.

v5.0.0(10y ago)16520.8k44[5 issues](https://github.com/Toddish/Verify-L4/issues)[1 PRs](https://github.com/Toddish/Verify-L4/pulls)1MITPHPPHP &gt;=5.5.9

Since Mar 19Pushed 10y ago19 watchersCompare

[ Source](https://github.com/Toddish/Verify-L4)[ Packagist](https://packagist.org/packages/toddish/verify)[ Docs](http://docs.toddish.co.uk/verify-l4/)[ RSS](/packages/toddish-verify/feed)WikiDiscussions develop Synced 3w ago

READMEChangelogDependencies (1)Versions (25)Used By (1)

Verify - Laravel 5 Auth Package
===============================

[](#verify---laravel-5-auth-package)

---

A simple role/permission authentication package for Laravel 5.1

For Laravel 5.0, use Verify 4.*.
For Laravel 4.2, use Verify 3.*.
For Laravel &lt; 4.2, use Verify 2.\*.

---

- Secure password storage with salt
- Role/permission based authentication
- Exceptions for intelligent handling of errors
- Configurable/extendable
- Licensed under the MIT license

---

Installation
------------

[](#installation)

Add Verify to your composer.json file:

```
"require": {
	"toddish/verify": "~5"
}

```

Now, run a composer update on the command line from the root of your project:

```
composer update

```

### Registering the Package

[](#registering-the-package)

Add the Verify Service Provider to your config in `app/config/app.php`:

```
'providers' => [
	'Toddish\Verify\Providers\VerifyServiceProvider
],
```

### Change the driver

[](#change-the-driver)

Then change your Auth driver to `'verify'` in `app/config/auth.php`:

```
'driver' => 'verify',
```

You may also change the `'model'` value to `'Toddish\Verify\Models\User'` if you want to be able to load Verify's User model when using `Auth::user()`.

Alternatively, you can simply create your own User model, and extend Verify's:

```
use Toddish\Verify\Models\User as VerifyUser;

class User extends VerifyUser
{
    // Code
}
```

### Publish the assets

[](#publish-the-assets)

Run this on the command line from the root of your project:

```
php artisan vendor:publish

```

Or, if you want to publish parts of Verify individually:

```
php artisan vendor:publish --provider="Toddish\Verify\Providers\VerifyServiceProvider" --tag="config"

```

The available tags are **config**, **migrations** and **seeds**.

### Migration

[](#migration)

Now migrate the database tables for Verify. Run these on the command line from the root of your project:

```
php artisan migrate
php artisan db:seed

```

You should now have all the tables imported, complete with a sample user, called **admin**, with a password of **password**.

Usage
-----

[](#usage)

The package is intentionally lightweight. You add Users, Roles and Permissions like any other Model.

```
$user = new Toddish\Verify\Models\User;
$role = new Toddish\Verify\Models\Role;
$permission = new Toddish\Verify\Models\Permission;
```

etc.

**All models are in the namespace 'Toddish\\Verify\\Models'.**

The relationships are as follows:

- Roles have many and belong to Users
- Users have many and belong to Roles
- Roles have many and belong to Permissions
- Permissions have many and belong to Roles

Relationships are handled via the Eloquent ORM, too:

```
$role->permissions()->sync([$permission->id, $permission2->id]);
```

More information on relationships can be found in the [Laravel 5 Eloquent docs](http://laravel.com/docs/eloquent).

Basic Examples
--------------

[](#basic-examples)

```
// Create a new Permission
$permission = new Toddish\Verify\Models\Permission;
$permission->name = 'delete_user';
$permission->save();

// Create a new Role
$role = new Toddish\Verify\Models\Role;
$role->name = 'Moderator';
$role->level = 7;
$role->save();

// Assign the Permission to the Role
$role->permissions()->sync([$permission->id]);

// Create a new User
$user = new Toddish\Verify\Models\User;
$user->username = 'Todd';
$user->email = 'todd@toddish.co.uk';
$user->password = 'password'; // This is automatically salted and encrypted
$user->save();

// Assign the Role to the User
$user->roles()->sync(array($role->id));

// Using the public methods available on the User object
var_dump($user->is('Moderator')); // true
var_dump($user->is('Admin')); // false

var_dump($user->can('delete_user')); // true
var_dump($user->can('add_user')); // false

var_dump($user->level(7)); // true
var_dump($user->level(5, '
