Download the PHP package baklysystems/laravel-permission without Composer
On this page you can find all versions of the php package baklysystems/laravel-permission. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download baklysystems/laravel-permission
More information about baklysystems/laravel-permission
Files in baklysystems/laravel-permission
Package laravel-permission
Short Description Permission handling for Laravel 5.1
License MIT
Homepage https://github.com/spatie/laravel-permission
Informations about the package laravel-permission
Associate users with roles and permissions
This package allows to save permissions and roles in a database. It is built upon Laravel's authorization functionality that was introduced in version 5.1.11
Once installed you can do stuff like this:
You can test if a user has a permission with Laravel's default can
-function.
If you want a drop-in middleware to check permissions, check out our authorize package: https://github.com/spatie/laravel-authorize
Spatie is webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Install
You can install the package via composer:
This service provider must be installed.
You can publish the migration with:
The package assumes that your users table name is called "users". If this is not the case you should manually edit the published migration to use your custom table name.
After the migration has been published you can create the role- and permission-tables by running the migrations:
You can publish the config-file with:
This is the contents of the published config file:
Usage
First add the Spatie\Permission\Traits\HasRoles
-trait to your User model.
This package allows for users to be associated with roles. Permissions can be associated with roles.
A Role
and a Permission
are regular Eloquent-models. They can have a name and can be created like this:
The HasRoles
adds eloquent relationships to your models, which can be accessed directly or used as a base query.
Using permissions
A permission can be given to a user:
A permission can be revoked from a user:
You can test if a user has a permission:
Saved permissions will be registered with the Illuminate\Auth\Access\Gate
-class. So you can
test if a user has a permission with Laravel's default can
-function.
Using roles and permissions
A role can be assigned to a user:
A role can be removed from a user:
You can determine if a user has a certain role:
You can also determine if a user has any of a given list of roles:
You can also determine if a user has all of a given list of roles:
The assignRole
, hasRole
, hasAnyRole
, hasAllRoles
and removeRole
-functions can accept a
string, a Spatie\Permission\Models\Role
-object or an \Illuminate\Support\Collection
-object.
A permission can be given to a role:
A permission can be revoked from a role:
The givePermissionTo
and revokePermissionTo
-functions can accept a
string or a Spatie\Permission\Models\Permission
-object.
Saved permission and roles are also registered with the Illuminate\Auth\Access\Gate
-class.
Using blade directives
This package also adds Blade directives to verify whether the currently logged in user has all or any of a given list of roles.
You can use Laravel's native @can
directive to check if a user has a certain permission.
Extending
If you need to extend or replace the existing Role
or Permission
models you just need to
keep the following things in mind:
- Your
Role
model needs to implement theSpatie\Permission\Contracts\Role
contract - Your
Permission
model needs to implement theSpatie\Permission\Contracts\Permission
contract - You must publish the configuration with this command:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"
and update themodels.role
andmodels.permission
values
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Freek Van der Herten
- All Contributors
This package is heavily based on Jeffrey Way's awesome Laracasts-lesson on roles and permissions. His original code can be found in this repo on GitHub.
Alternatives
About Spatie
Spatie is webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
License
The MIT License (MIT). Please see License File for more information.