Looking to hire Laravel developers? Try LaraJobs

laravel-user-management maintained by jscustom

Description
Laravel package for user management. Includes user, user profile and user role.
Last update
2022/11/01 02:28 (dev-master)
License
Links
Downloads
25

Comments
comments powered by Disqus

Laravel User Management API

Laravel package for user management. Includes user, user profile and user role.

Table of Contents

Getting Started Compatible Packages Installation How to Use Download Postman API User Management Create User API Update User API View User API User List API Delete User API User Role Management Create User Role API Update User Role API View User Role API User Role List API Delete User Role API Support

Getting Started

Below are the steps in order to integrate user management API to your Laravel project.

Compatible Packages

This package works well with Laravel Sanctum.

Installation

Install the package using composer:

composer require jscustom/laravel-user-management

Export the configuration file:

php artisan vendor:publish --provider="JSCustom\LaravelUserManagement\Providers\LaravelUserManagementServiceProvider" --tag="config"

Export the migration files:

php artisan vendor:publish --provider="JSCustom\LaravelUserManagement\Providers\LaravelUserManagementServiceProvider" --tag="migrations"

Do a quick migration:

php artisan migrate --path=/database/migrations/laravel-user-management

How To Use

Download Postman API

Download the Postman API Collection here.

User Management

Features

  • Create User
  • Update User
  • View User Details
  • View UserList
  • Delete User

Models

JSCustom\LaravelUserManagement\Models\User
JSCustom\LaravelUserManagement\Models\UserAddress
JSCustom\LaravelUserManagement\Models\UserProfile

Create User API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController

URL

{{url}}/api/user

Form Data

{
  "username": "stevengrant",
  "email": "stevengrant@mail.com",
  "status": 1,
  "role_id": 1,
  "first_name": "Steven",
  "last_name": "Grant",
}

Method

POST

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "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"
      }
    }
  }
}

Update User API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController

URL

{{url}}/api/user/$id

Form Data

{
  "username": "stevengrant",
  "email": "stevengrant@mail.com",
  "status": 1,
  "role_id": 1,
  "first_name": "Steven",
  "last_name": "Grant"
}

Method

POST

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "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"
      }
    }
  }
}

View User API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController

URL

{{url}}/api/user/$id

Method

GET

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "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"
      }
    }
  }
}

User List API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController

URL

{{url}}/api/user/list

Parameters

{
  "page": 1,
  "limit": 10,
  "q": '<search_string>',
  "order_column": '<column_name>',
  "order_direction": "asc",
  "created_from": "2022-01-01",
  "created_to": "2022-05-31"
}

Method

GET

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "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": "&laquo; Previous",
          "active": false
        },
        {
          "url": "http://127.0.0.1:8000/api/user/list?page=1",
          "label": "1",
          "active": true
        },
        {
          "url": null,
          "label": "Next &raquo;",
          "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
    }
  }
}

Delete User API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\User\UserController

URL

{{url}}/api/user/$id

Method

DELETE

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "status": true,
  "message": "User has been deleted."
}

User Role Management

Features

  • Create User Role
  • Update User Role
  • View User Role Details
  • View User Role List
  • Delete User Role

Models

JSCustom\LaravelUserManagement\Models\UserRole

Create User Role API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController

URL

{{url}}/api/user-role

Form Data

{
  "role": "Staff",
  "description": "Have access to staff level functions"
}

Method

POST

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "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
    }
  }
}

Update User Role API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController

URL

{{url}}/api/user-role/$id

Form Data

{
  "role": "Staff",
  "description": "Have access to staff level functions"
}

Method

POST

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "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"
    }
  }
}

View User Role API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController

URL

{{url}}/api/user-role/$id

Method

GET

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "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"
    }
  }
}

User Role List API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController

URL

{{url}}/api/user-role/list

Parameters

{
  "page": 1,
  "limit": 10,
  "q": '<search_string>',
  "order_column": '<column_name>',
  "order_direction": "asc",
  "created_from": "2022-01-01",
  "created_to": "2022-05-31"
}

Method

GET

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "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": "&laquo; Previous",
          "active": false
        },
        {
          "url": "http://127.0.0.1:8000/api/user-role/list?page=1",
          "label": "1",
          "active": true
        },
        {
          "url": null,
          "label": "Next &raquo;",
          "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
    }
  }
}

Delete User Role API

Controller

\JSCustom\LaravelUserManagement\Http\Controllers\UserRole\UserRoleController

URL

{{url}}/api/user-role/$id

Method

DELETE

Headers (Note: Authorization is not required if sanctum > enabled = false in config/user.php)

{
  "Authorization": "Bearer ...",
  "Accept": "application/json"
}

Response

{
  "status": true,
  "message": "User role has been deleted."
}

Support

For support, email developer.jeddsaliba@gmail.com.