jscustom / laravel-user-management
Laravel 用户管理包。包括用户、用户资料和用户角色。
Requires
- php: ^7.0|^8.0
- illuminate/support: ^7.0|^8.0
Requires (Dev)
- phpunit/phpunit: ^5.0 || ^6.0 || ^7.0
This package is auto-updated.
Last update: 2024-09-29 06:25:56 UTC
README
Laravel 用户管理包。包括用户、用户资料和用户角色。
目录
入门指南
兼容包
安装
如何使用
下载Postman API
用户管理
创建用户API
更新用户API
查看用户API
用户列表API
删除用户API
用户角色管理
创建用户角色API
更新用户角色API
查看用户角色API
用户角色列表API
删除用户角色API
支持
入门指南
以下是将用户管理API集成到您的Laravel项目的步骤。
兼容包
此包与 Laravel Sanctum 一起工作得很好。
安装
使用composer安装此包
composer require jscustom/laravel-user-management
导出配置文件
php artisan vendor:publish --provider="JSCustom\LaravelUserManagement\Providers\LaravelUserManagementServiceProvider" --tag="config"
导出迁移文件
php artisan vendor:publish --provider="JSCustom\LaravelUserManagement\Providers\LaravelUserManagementServiceProvider" --tag="migrations"
执行快速迁移
php artisan migrate --path=/database/migrations/laravel-user-management
如何使用
下载Postman API
在此处下载Postman API集合 这里.
用户管理
功能
- 创建用户
- 更新用户
- 查看用户详情
- 查看用户列表
- 删除用户
模型
JSCustom\LaravelUserManagement\Models\User JSCustom\LaravelUserManagement\Models\UserAddress JSCustom\LaravelUserManagement\Models\UserProfile
创建用户API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController
URL
{{url}}/api/user
表单数据
{ "username": "stevengrant", "email": "stevengrant@mail.com", "status": 1, "role_id": 1, "first_name": "Steven", "last_name": "Grant", }
方法
POST
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "status": true, "message": "User has been saved.", "payload": { "user": { "username": "stevengrant", "email": "stevengrant@mail.com", "status": 1, "role_id": 1, "updated_at": "2022-05-23T07:52:41.000000Z", "created_at": "2022-05-23T07:52:41.000000Z", "id": 2, "password_unhashed": "X2QQTVZZ", "user_role": { "id": 1, "role": "Developer", "description": "Developer", "created_at": "2022-05-23T15:52:12.000000Z", "updated_at": "2022-05-23T15:52:12.000000Z" }, "user_profile": { "id": 2, "user_id": 2, "first_name": "Steven", "last_name": "Grant", "created_at": "2022-05-23T07:52:41.000000Z", "updated_at": "2022-05-23T07:52:41.000000Z" }, "user_address": { "id": 2, "user_id": 2, "line_1": null, "line_2": null, "city_id": null, "province_id": null, "postal_code": null, "country_id": null, "other_address_details": null, "created_at": "2022-05-23T07:52:41.000000Z", "updated_at": "2022-05-23T07:52:41.000000Z" } } } }
更新用户API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController
URL
{{url}}/api/user/$id
表单数据
{ "username": "stevengrant", "email": "stevengrant@mail.com", "status": 1, "role_id": 1, "first_name": "Steven", "last_name": "Grant" }
方法
POST
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "status": true, "message": "User has been saved.", "payload": { "user": { "id": 2, "username": "stevengrant", "email": "stevengrant@mail.com", "status": 1, "role_id": 1, "email_verified_at": null, "created_at": "2022-05-23T07:52:41.000000Z", "updated_at": "2022-05-23T07:54:02.000000Z", "password_unhashed": "OHYY0NB6", "user_role": { "id": 1, "role": "Developer", "description": "Developer", "created_at": "2022-05-23T15:52:12.000000Z", "updated_at": "2022-05-23T15:52:12.000000Z" }, "user_profile": { "id": 2, "user_id": 2, "first_name": "Steven", "last_name": "Grant", "created_at": "2022-05-23T07:52:41.000000Z", "updated_at": "2022-05-23T07:52:41.000000Z" }, "user_address": { "id": 2, "user_id": 2, "line_1": null, "line_2": null, "city_id": null, "province_id": null, "postal_code": null, "country_id": null, "other_address_details": null, "created_at": "2022-05-23T07:52:41.000000Z", "updated_at": "2022-05-23T07:52:41.000000Z" } } } }
查看用户API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController
URL
{{url}}/api/user/$id
方法
GET
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "status": true, "message": "User found.", "payload": { "user": { "id": 2, "username": "stevengrant", "email": "stevengrant@mail.com", "status": 1, "role_id": 1, "email_verified_at": null, "created_at": "2022-05-23T07:52:41.000000Z", "updated_at": "2022-05-23T07:54:02.000000Z", "user_role": { "id": 1, "role": "Developer", "description": "Developer", "created_at": "2022-05-23T15:52:12.000000Z", "updated_at": "2022-05-23T15:52:12.000000Z" }, "user_profile": { "id": 2, "user_id": 2, "first_name": "Steven", "last_name": "Grant", "created_at": "2022-05-23T07:52:41.000000Z", "updated_at": "2022-05-23T07:52:41.000000Z" }, "user_address": { "id": 2, "user_id": 2, "line_1": null, "line_2": null, "city_id": null, "province_id": null, "postal_code": null, "country_id": null, "other_address_details": null, "created_at": "2022-05-23T07:52:41.000000Z", "updated_at": "2022-05-23T07:52:41.000000Z" } } } }
用户列表API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController
URL
{{url}}/api/user/list
参数
{ "page": 1, "limit": 10, "q": '<search_string>', "order_column": '<column_name>', "order_direction": "asc", "created_from": "2022-01-01", "created_to": "2022-05-31" }
方法
GET
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "message": "Users found.", "payload": { "users": { "current_page": 1, "data": [ { "id": 1, "username": "developer", "email": "developer@mail.com", "created_at": "2022-05-23T15:52:12.000000Z", "first_name": "Developer", "last_name": "Developer", "line_1": null, "line_2": null, "postal_code": null, "other_address_details": null, "role": "Developer" }, { "id": 3, "username": "jakelockley", "email": "jakelockley@mail.com", "created_at": "2022-05-23T07:55:58.000000Z", "first_name": "Jake", "last_name": "Lockley", "line_1": null, "line_2": null, "postal_code": null, "other_address_details": null, "role": "Developer" }, { "id": 4, "username": "marcspector", "email": "marcspector@mail.com", "created_at": "2022-05-23T07:56:15.000000Z", "first_name": "Marc", "last_name": "Spector", "line_1": null, "line_2": null, "postal_code": null, "other_address_details": null, "role": "Developer" }, { "id": 2, "username": "stevengrant", "email": "stevengrant@mail.com", "created_at": "2022-05-23T07:52:41.000000Z", "first_name": "Steven", "last_name": "Grant", "line_1": null, "line_2": null, "postal_code": null, "other_address_details": null, "role": "Developer" } ], "first_page_url": "http://127.0.0.1:8000/api/user/list?page=1", "from": 1, "last_page": 1, "last_page_url": "http://127.0.0.1:8000/api/user/list?page=1", "links": [ { "url": null, "label": "« Previous", "active": false }, { "url": "http://127.0.0.1:8000/api/user/list?page=1", "label": "1", "active": true }, { "url": null, "label": "Next »", "active": false } ], "next_page_url": null, "path": "http://127.0.0.1:8000/api/user/list", "per_page": "10", "prev_page_url": null, "to": 4, "total": 4 } } }
删除用户API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController
URL
{{url}}/api/user/$id
方法
DELETE
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "status": true, "message": "User has been deleted." }
用户角色管理
功能
- 创建用户角色
- 更新用户角色
- 查看用户角色详情
- 查看用户角色列表
- 删除用户角色
模型
JSCustom\LaravelUserManagement\Models\UserRole
创建用户角色API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController
URL
{{url}}/api/user-role
表单数据
{ "role": "Staff", "description": "Have access to staff level functions" }
方法
POST
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "status": true, "message": "User role been saved.", "payload": { "user_role": { "role": "Staff", "description": "Have access to administrator level functions", "updated_at": "2022-05-23T08:01:10.000000Z", "created_at": "2022-05-23T08:01:10.000000Z", "id": 2 } } }
更新用户角色API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController
URL
{{url}}/api/user-role/$id
表单数据
{ "role": "Staff", "description": "Have access to staff level functions" }
方法
POST
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "status": true, "message": "User role been saved.", "payload": { "user_role": { "id": 2, "role": "Staff", "description": "Have access to staff level functions", "created_at": "2022-05-23T08:01:10.000000Z", "updated_at": "2022-05-23T08:02:27.000000Z" } } }
查看用户角色API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController
URL
{{url}}/api/user-role/$id
方法
GET
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "status": true, "message": "User role found.", "payload": { "user_role": { "id": 2, "role": "Staff", "description": "Have access to staff level functions", "created_at": "2022-05-23T08:01:10.000000Z", "updated_at": "2022-05-23T08:02:27.000000Z" } } }
用户角色列表API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController
URL
{{url}}/api/user-role/list
参数
{ "page": 1, "limit": 10, "q": '<search_string>', "order_column": '<column_name>', "order_direction": "asc", "created_from": "2022-01-01", "created_to": "2022-05-31" }
方法
GET
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "message": "User roles found.", "payload": { "user_roles": { "current_page": 1, "data": [ { "id": 1, "role": "Developer", "description": "Developer", "created_at": "2022-05-23T15:52:12.000000Z", "updated_at": "2022-05-23T15:52:12.000000Z" }, { "id": 2, "role": "Staff", "description": "Have access to staff level functions", "created_at": "2022-05-23T08:01:10.000000Z", "updated_at": "2022-05-23T08:02:27.000000Z" } ], "first_page_url": "http://127.0.0.1:8000/api/user-role/list?page=1", "from": 1, "last_page": 1, "last_page_url": "http://127.0.0.1:8000/api/user-role/list?page=1", "links": [ { "url": null, "label": "« Previous", "active": false }, { "url": "http://127.0.0.1:8000/api/user-role/list?page=1", "label": "1", "active": true }, { "url": null, "label": "Next »", "active": false } ], "next_page_url": null, "path": "http://127.0.0.1:8000/api/user-role/list", "per_page": "10", "prev_page_url": null, "to": 2, "total": 2 } } }
删除用户角色API
控制器
\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController
URL
{{url}}/api/user-role/$id
方法
DELETE
头部
(注意:如果 config/user.php
中的 sanctum > enabled = false
,则不需要 Authorization
)
{ "Authorization": "Bearer ...", "Accept": "application/json" }
响应
{ "status": true, "message": "User role has been deleted." }
支持
如有支持问题,请发送电子邮件至 developer.jeddsaliba@gmail.com。