2017 © Pedro Peláez
 

library laravel-auth

A simple extension of laravel's authentication.

image

jeroen-g/laravel-auth

A simple extension of laravel's authentication.

  • Monday, September 1, 2014
  • by JeroenG
  • Repository
  • 2 Watchers
  • 7 Stars
  • 222 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Auth

Just another authentication package for Laravel.

Build Status Scrutinizer Quality Score Latest Stable Version, (*1)


Installation

Add this line to your composer.json, (*2)

"jeroen-g/laravel-auth": "dev-master"

Then update Composer, (*3)

composer update

Add the service provider in app/config/app.php:, (*4)

'JeroenG\LaravelAuth\LaravelAuthServiceProvider',

The last thing to do is to migrate to create the tables for the users, roles and permissions, (*5)

php artisan migrate --package="jeroen-g/laravel-auth"

Usage

Check if the user has a permission

if(Auth::can('edit'))
{
    // show a form to edit stuff.
}

Check if the user has a role

if(Auth::is('Moderator'))
{
    // Show a form to edit stuff, if the 'Moderator' role has the 'edit' permission.
}

Check if the user is an admin

To use this function, make sure to give a user the 'Admin' role., (*6)

Auth::isAdmin();

You could for example use this to create a filter that protects your backend., (*7)

Route::filter('auth.admin', function()
{
    if ( ! Auth::isAdmin()) return Redirect::to('login');
});

Getting all of the available roles/permissions/users

Auth::allRoles();

Auth::allPermissions();

Auth::allUsers();

//Example of both optional parameter
Auth::allUsers('json', true);

Both accept two optional parameters, which is the format of the returned results: array, object or json. By default an array is returned. The second is a boolean, set this to true if you want to include trashed items., (*8)

Assigning a role/permission to a user

Auth::giveRole('Member', 2);

Auth::givePermission('edit', 2);

In both cases the second parameter is the user id. This is optional, if none is passed, the id of the logged in user is used., (*9)

Assiging a permission to a role

Auth::giveRolePermission('edit', 'Admin');

The first parameter is the permission, the second the role. To find out if a role has a certain permission, you could use the roleCan() function., (*10)

Auth::roleCan('Admin', 'edit');

Removing a role/permission from a user/role

Auth::takeRole('Member', 2);

Auth::takePermission('edit', 2);

Auth::takeRolePermission('edit', 'Admin');

Check if a role/permission/user exists

Auth::roleExists('Admin');

Auth::permissionExists('edit');

Auth::userExists(2);

All three functions accept a second parameter, true or false, which determines if the trashed entries will also be used (trashed entries are soft-deleted from the database, see below)., (*11)

Adding a new role/permission/user

// Name, description, level (any number)
Auth::addRole('Admin', 'One Role To Rule Them All', 10);

// Name, description
Auth::addPermission('edit', 'Ability to edit stuff');

// Username, password, email
Auth::addUser('Jeroen', 'password123', 'jeroen@example.com');

Delete a role/permission/user

Auth::deleteRole('Moderator');

Auth::deletePermission('edit', true);

Auth::deleteUser(2);

A second parameter is accepted on all three functions. This boolean states if the entry (role/perm/user) should be deleted with force (default set to false). Soft-deleted (so not with force) will be left out of every request to the database (unless otherwise stated). They can however be restored., (*12)

The Versions

01/09 2014

dev-master

9999999-dev

A simple extension of laravel's authentication.

  Sources   Download

EUPL-1.1

The Requires

 

by Jeroen G

laravel authentication auth login users

01/09 2014

dev-L4.3

dev-L4.3

A simple extension of laravel's authentication.

  Sources   Download

EUPL-1.1

The Requires

 

by Jeroen G

laravel authentication auth login users

10/03 2014

v1.0-beta

1.0.0.0-beta

A simple extension of laravel's authentication.

  Sources   Download

EUPL-1.1

The Requires

 

The Development Requires

by Jeroen G

laravel authentication auth login users