Skip to main content
General - Roles API Documentation and Postman Guide.
This document is based on the current Laravel source code in:
The Roles API in this project is intentionally small:
  • list roles
  • show a role
  • update a role label/description
  • assign permissions to a role for a specific company
There is currently no exposed API route to create or delete roles.

Table of Contents

  1. Base URL and Auth
  2. Seeded Roles
  3. How Role Permissions Work in This Project
  4. Authorization Notes
  5. Common Permission IDs Related to Roles and Users
  6. Endpoints
    • 6.1 List Roles
    • 6.2 Show Role
    • 6.3 Update Role
    • 6.4 Assign Permissions to a Role
  7. Postman Examples
    • 7.1 Fetch All Roles for Company 1
    • 7.2 Fetch Instructor Role
    • 7.3 Update Instructor Role Description
    • 7.4 Give Instructor Role a Minimal User-Management Set
  8. Known Implementation Notes
    • 8.1 Roles Are Seeded, Not Created by API
    • 8.2 Company Context Matters
    • 8.3 Use Admin or Super-Admin for Testing
    • 8.4 Permission Assignment Is a Sync Operation
  9. Recommended Postman Test Order

1. Base URL and Auth

Base API URL:
Recommended Postman variables: Required headers for protected endpoints:
All documented role endpoints are inside the authenticated company-protected route group.

2. Seeded Roles

These roles are inserted by DatabaseSeeder.php: Important note:
  • role labels are seeded once
  • you can update them through the API
  • users reference roles through users.role_id

3. How Role Permissions Work in This Project

The relationship is:
The pivot table stores:
  • role_id
  • permission_id
  • company_id
That means permissions are company-specific. Practical meaning:
  • the same role can return different permissions depending on the company_id
  • when you list or show roles, you should send company_id
  • role permissions are filtered using wherePivot('company_id', request('company_id'))

4. Authorization Notes

According to RolePolicy.php:
  • viewAny is allowed for super-admin, admin, or users with the roles-viewAny permission
  • view is allowed for super-admin, admin, or users with roles-view only when user.role_id === role.id
  • update is allowed for super-admin, admin, or users with roles-edit only when user.role_id === role.id
  • assign_permissions is restricted to admin and super-admin
Practical testing advice:
  • use an Admin or Super-Admin token in Postman for the role endpoints
Useful permission IDs from App\Models\Permission: If you need the complete permission catalog, use the permissions endpoints or inspect app/Models/Permission.php.

6. Endpoints

6.1 List Roles

Returns all roles with permissions filtered for the specified company. Query Parameters Example Request
Success Response
Notes:
  • the controller validates company_id
  • permissions are returned only for the requested company

6.2 Show Role

Returns one role with permissions filtered by company_id. Recommended Query Parameter Example Request
Success Response
Important note:
  • unlike the index endpoint, show() does not explicitly validate company_id
  • but you should still send it, otherwise permissions may come back empty

6.3 Update Role

Updates the role label and description. This endpoint uses POST, not PUT. Request JSON
Success Response
Validation Error Example
Notes:
  • label is required
  • description is also required by the controller, even though the database column itself is nullable

6.4 Assign Permissions to a Role

Replaces the role’s permission set using syncWithPivotValues(). Request JSON
Success Response
Validation Error Example
Important behavior:
  • treat this endpoint as a full replace, not an incremental add
  • send the full final list of permission IDs you want for that role/company
  • if you send only one new permission, the others can be removed by sync behavior

7. Postman Examples

7.1 Fetch All Roles for Company 1

7.2 Fetch Instructor Role

7.3 Update Instructor Role Description

7.4 Give Instructor Role a Minimal User-Management Set

8. Known Implementation Notes

8.1 Roles Are Seeded, Not Created by API

Current routes only support:
  • list
  • show
  • update
  • assign permissions
There is no exposed route for:
  • create role
  • archive role
  • unarchive role
  • delete role

8.2 Company Context Matters

The same role object can show different permissions depending on company_id. Always send:
when reading role permissions.

8.3 Use Admin or Super-Admin for Testing

Because of the current policies, the safest Postman user for roles testing is:
  • Admin
  • or Super-Admin

8.4 Permission Assignment Is a Sync Operation

assign_permissions() uses:
So the request should contain the full target permission set, not only the delta.
  1. Login as an admin or super-admin
  2. Call GET /api/roles?company_id=1
  3. Call GET /api/role/2?company_id=1
  4. Update a role description with POST /api/role/{id}
  5. Assign a complete permission list with POST /api/role/{id}/assign_permissions
  6. Re-fetch the role to confirm the permission pivot rows for that company