Download the PHP package mark-villudo/laravel-user-management without Composer
On this page you can find all versions of the php package mark-villudo/laravel-user-management. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mark-villudo/laravel-user-management
More information about mark-villudo/laravel-user-management
Files in mark-villudo/laravel-user-management
Package laravel-user-management
Short Description Permission handling for Laravel 5.1 and up
License MIT
Homepage https://github.com/MarkVilludo/laravel-user-management
Informations about the package laravel-user-management
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 specific permission and module name.
Licensed
You're free to use this package (it's MIT-licensed), but if it makes it to your production environment we highly appreciate you sending us a message.
Installation
You can install the package via Composer:
Now add the service provider in config/app.php
file:
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 Initial Permission Seeder, then update it's content depending on your needs.
You can publish the config-file with:
This is the contents of the published config/laravel-permission.php
config file:
You can publish the views with:
You can publish the public assets with:
Usage
First add the MarkVilludo\Permission\Traits\HasRoles
trait to your User model, then paste the ff code below.
Setup env
We send password in add new user. \n So we need to Define each mail driver, username, password, encryption and mail from. ex:
Setup User Resource: php artisan make: resource UserResource
Define each return data from user table.
Setup Role Resource: php artisan make: resource RoleResource
Define each return data from roles table and it's permissions.
Access User Management pages
To access the package controller by placing another \ in front you tell Laravel to start searching in the root namespace.
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. Role 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:
The HasRoles
also adds a scope to your models to scope the query to certain roles:
The scope can accept a string, a MarkVilludo\Permission\Models\Role
object or an \Illuminate\Support\Collection
object.
Using permissions check if can access in specific permission Add
in Users
module.
Using roles and permissions
A role can be assigned to a user:
A role can be removed from a user:
Roles can also be synced:
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 MarkVilludo\Permission\Models\Role
object or an \Illuminate\Support\Collection
object.
A permission can be given to a role:
You can determine if a role has a certain permission:
A permission can be revoked from a role:
You can list all of theses permissions:
All theses responses are collections of Spatie\Permission\Models\Permission
objects.
If we follow the previous example, the first response will be a collection with the 'delete article' permission, the second will be a collection with the 'edit article' permission and the third will contain both.
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.
Using a middleware
The package doesn't contain a middleware to check permissions but it's very trivial to add this yourself:
This will create a app/Http/Middleware/RoleMiddleware.php
file for you, where you can handle your role and permissions check:
Don't forget to add the route middleware to app/Http/Kernel.php
file:
Now you can protect your routes using the middleware you just set up:
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 theMarkVilludo\Permission\Contracts\Role
contract - Your
Permission
model needs to implement theMarkVilludo\Permission\Contracts\Permission
contract -
You must publish the configuration with this command:
And update the
models.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]]
Credits
- Spatie
- Freek Van der Herten
This package is heavily based on Jeffrey Way's awesome Laracasts lessons on roles and permissions. His original code can be found in this repo on GitHub.
Alternatives
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-user-management with dependencies
laravel/framework Version ~5.1.11|~5.2.0|~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0
laravelcollective/html Version ^5.4.0
illuminate/contracts Version ~5.1.0|~5.2.0|~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0