Manage all of the users, we use "spatie/laravel-permission" package for manage all of the users.
When you installing this package the "spatie/laravel-permission" package and dependencies will be install automatically.
In "LaravelUserManagement" package we create all of the DB Tables, Entities, Seeders, View for manage users, roles, permissions and departments.
Installation
Install the package via composer:
composer require mekaeil/laravel-user-management
Add the service providers in your config/app.php file:
After publishing vendors, add this code to "run" method in database/DatabaseSeeder.php
public function run()
{
/*
|--------------------------------------------------------------------------
| SEEDERS FOR LARAVEL USER MANAGEMENT
|--------------------------------------------------------------------------
|
*/
$this->call(RoleTableSeeder::class);
$this->call(PermissionTableSeeder::class);
$this->call(DepartmentTableSeeder::class);
}
Now it's important to change config if you want(laravel_user_management): (you can skip it)
/*
|--------------------------------------------------------------------------
| LARAVEL USER MANAGEMENT CONFIG
|--------------------------------------------------------------------------
|
|
*/
// laravel_user_management.users_table
'users_table' => 'users',
// laravel_user_management.user_department_table
'user_department_table' => 'user_departments',
/**
* THIS TABLE IS NAME OF THE MANY TO MANY RELATIONAL TABLE
* BETWEEN USERS TABLE & USER DEPARTMENTS TABLE
* **/
// laravel_user_management.user_department_user_table
'user_department_user_table' => 'user_departments_users',
// laravel_user_management.password_resets_table
'password_resets_table' => 'user_password_resets',
// laravel_user_management.user_model
'user_model' => App\Entities\User::class,
// laravel_user_management.row_list_per_page
'row_list_per_page' => 15,
// laravel_user_management.admin_url
'admin_url' => env('APP_URL').'/admin',
// laravel_user_management.logo_url
'logo_url'=> env('APP_URL'). "/mekaeils-package/images/logo-user-management.jpg",
'auth' => [
// laravel_user_management.auth.enable
'enable' => true,
// laravel_user_management.auth.login_url
'login_url' => 'user/login',
// laravel_user_management.auth.register_url
'register_url' => 'user/register',
// laravel_user_management.auth.logout_url
'logout_url' => 'user/logout',
// laravel_user_management.auth.username
'username' => 'email', // email OR mobile
/**
* DEFAULT ROLE FOR USERS WANT TO REGISTER ON WEBSITE
* YOU SHOULD DEFINE THIS ROLE IN SEEDER OR CREATE IT IN ADMIN PANEL
* **/
// laravel_user_management.auth.user_default_role
'user_default_role' => 'User',
/**
* DEFAULT STATUS FOR USERS WANT TO REGISTER ON WEBSITE
* IF IT'S SET ON 'PENDING' USER CAN NOT LOGIN IN WEBSITE
* AND NEED TO ACCEPT BY ADMINISTRATOR
* **/
// laravel_user_management.auth.default_user_status
'default_user_status' =>'accepted', /// 'pending','accepted','blocked'
// laravel_user_management.auth.dashboard_route_name_user_redirection
'dashboard_route_name_user_redirection' => 'home' /// ** ROUTE NAME **
],
And if set permissions table if you want to customize it: (you can skip it)
'models' => [
/*
* When using the "HasPermissions" trait from this package, we need to know which
* Eloquent model should be used to retrieve your permissions. Of course, it
* is often just the "Permission" model but you may use whatever you like.
*
* The model you want to use as a Permission model needs to implement the
* `Spatie\Permission\Contracts\Permission` contract.
*/
// 'permission' => Spatie\Permission\Models\Permission::class,
'permission' => Spatie\Permission\Models\Permission::class,
/*
* When using the "HasRoles" trait from this package, we need to know which
* Eloquent model should be used to retrieve your roles. Of course, it
* is often just the "Role" model but you may use whatever you like.
*
* The model you want to use as a Role model needs to implement the
* `Spatie\Permission\Contracts\Role` contract.
*/
// 'role' => Spatie\Permission\Models\Role::class,
'role' => Spatie\Permission\Models\Role::class,
],
'table_names' => [
/*
* When using the "HasRoles" trait from this package, we need to know which
* table should be used to retrieve your roles. We have chosen a basic
* default value but you may easily change it to any table you like.
*/
'roles' => 'roles',
/*
* When using the "HasPermissions" trait from this package, we need to know which
* table should be used to retrieve your permissions. We have chosen a basic
* default value but you may easily change it to any table you like.
*/
'permissions' => 'permissions',
/*
* When using the "HasPermissions" trait from this package, we need to know which
* table should be used to retrieve your models permissions. We have chosen a
* basic default value but you may easily change it to any table you like.
*/
'model_has_permissions' => 'model_has_permissions',
/*
* When using the "HasRoles" trait from this package, we need to know which
* table should be used to retrieve your models roles. We have chosen a
* basic default value but you may easily change it to any table you like.
*/
'model_has_roles' => 'model_has_roles',
/*
* When using the "HasRoles" trait from this package, we need to know which
* table should be used to retrieve your roles permissions. We have chosen a
* basic default value but you may easily change it to any table you like.
*/
'role_has_permissions' => 'role_has_permissions',
],
'column_names' => [
/*
* Change this if you want to name the related model primary key other than
* `model_id`.
*
* For example, this would be nice if your primary keys are all UUIDs. In
* that case, name this `model_uuid`.
*/
'model_morph_key' => 'model_id',
],
/*
* When set to true, the required permission/role names are added to the exception
* message. This could be considered an information leak in some contexts, so
* the default setting is false here for optimum safety.
*/
'display_permission_in_exception' => false,
'cache' => [
/*
* By default all permissions are cached for 24 hours to speed up performance.
* When permissions or roles are updated the cache is flushed automatically.
*/
'expiration_time' => \DateInterval::createFromDateString('24 hours'),
/*
* The cache key used to store all permissions.
*/
'key' => 'spatie.permission.cache',
/*
* When checking for a permission against a model by passing a Permission
* instance to the check, this key determines what attribute on the
* Permissions model is used to cache against.
*
* Ideally, this should match your preferred way of checking permissions, eg:
* `$user->can('view-posts')` would be 'name'.
*/
'model_key' => 'name',
/*
* You may optionally indicate a specific cache driver to use for permission and
* role caching using any of the `store` drivers listed in the cache.php config
* file. Using 'default' here means to use the `default` set in cache.php.
*/
'store' => 'default',
],
update your config/auth.php file:
use App\Entities\User;
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => config('laravel_user_management.password_resets_table'),
'expire' => 60,
],
],
];
After all of the steps run these commands ordinary.
5.1 php artisan migrate
5.2 php artisan db:seed
If you want to use Vue.js, change "laravel_user_management" config file:
/**
* IN THIS PACKAGE WE USE THE VUE.JS FOR PAGES IF YOU
* WANT TO USE IT, ENABLE IT AND FOLLOW INSTALLATION STEPS IN README FILE.
* **/
'vue_theme' => true,
Now follow USE VUE.JS FOR YOUR PROJECT section in bottom of this page.
Important
After vendor:publish files you should change user migration file, because we set
mobile and email to nullable, one of them you want to set to username should not nullable in Database.
```
$table->string('email')->nullable()->unique();
$table->string('mobile')->nullable()->unique();
```
Routes
After install package you can set this routes on your admin panel:
****
* IMPORTANT: THESE URL CAN BE CHANGE IN CONFIG FILE.
* THESE URLS ARE DEFAULT.
****
[method type: GET, url: domain.com/user/login ]
auth.user.login
[method type: POST, url: domain.com/user/login ]
auth.user.login
[method type: GET, url: domain.com/user/register ]
auth.user.register
[method type: POST, url: domain.com/user/register ]
auth.user.register
[method type: GET, url: domain.com/user/logout ]
auth.user.logout
Demo
login and registration
admin panel and create user
USE VUE.JS FOR YOUR PROJECT
If you want to use Vue.js for your project you can use the following installation instead of the bootstrap theme.
After installing package follow this steps:
1. npm install vue
2. Add this section to your package.json file:
"dependencies": {
"v-tooltip": "^2.0.2",
"vue-carousel": "^0.18.0",
"vue-clickaway": "^2.2.2",
"vue-lazyload": "^1.3.3",
"vue-material": "^1.0.0-beta-11",
"vue-router": "^3.1.3"
}
/**
* IN THIS PACKAGE WE USE THE VUE.JS FOR PAGES IF YOU
* WANT TO USE IT, ENABLE IT AND FOLLOW INSTALLATION STEPS IN README FILE.
* **/
'vue_theme' => true, // true, false | default: false
VUE JS DEMO
App Vue
Login
Register
Material Kit Theme
UPDATES
UPDATE PACKAGE FOR NEW VERSION OF THE LARAVEL => LARAVEL 6
VUE.JS FOR AUTH AND OTHER PAGES. (just vuejs theme without functinality like Auth,...)
IN PROGRESS
Adding functionality Auth in Vuejs theme.
Edit structure method for API response.
TEST
With this command you can running the test.
./vendor/bin/phpunit
License
The LaravelUserManagement is open-source software licensed under the MIT license.
Admin Template(PurpleAdmin-Free-Admin-Template) By Bootstrap Dash
请发表评论