Download the PHP package jeroen-g/laravel-auth without Composer
On this page you can find all versions of the php package jeroen-g/laravel-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-auth
Auth
Just another authentication package for Laravel.
Installation
Add this line to your composer.json
"jeroen-g/laravel-auth": "dev-master"
Then update Composer
composer update
Add the service provider in app/config/app.php
:
'JeroenG\LaravelAuth\LaravelAuthServiceProvider',
The last thing to do is to migrate to create the tables for the users, roles and permissions
php artisan migrate --package="jeroen-g/laravel-auth"
Usage
Check if the user has a permission
Check if the user has a role
Check if the user is an admin
To use this function, make sure to give a user the 'Admin' role.
You could for example use this to create a filter that protects your backend.
Getting all of the available roles/permissions/users
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.
Assigning a role/permission to a user
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.
Assiging a permission to a role
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.
Removing a role/permission from a user/role
Check if a role/permission/user exists
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).
Adding a new role/permission/user
Delete a role/permission/user
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.