General - Roles API Documentation and Postman Guide.
This document is based on the current Laravel source code in:- list roles
- show a role
- update a role label/description
- assign permissions to a role for a specific company
Table of Contents
- Base URL and Auth
- Seeded Roles
- How Role Permissions Work in This Project
- Authorization Notes
- Common Permission IDs Related to Roles and Users
- Endpoints
- 6.1 List Roles
- 6.2 Show Role
- 6.3 Update Role
- 6.4 Assign Permissions to a Role
- 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
- 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
- Recommended Postman Test Order
1. Base URL and Auth
Base API URL:{{base_url}}= http://127.0.0.1:8000{{token}}= your_sanctum_token
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:- role_id
- permission_id
- company_id
- 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:viewAnyis allowed for super-admin, admin, or users with theroles-viewAnypermissionviewis allowed for super-admin, admin, or users withroles-viewonly whenuser.role_id === role.idupdateis allowed for super-admin, admin, or users withroles-editonly whenuser.role_id === role.idassign_permissionsis restricted to admin and super-admin
- use an Admin or Super-Admin token in Postman for the role endpoints
5. Common Permission IDs Related to Roles and Users
Useful permission IDs fromApp\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
- the controller validates
company_id - permissions are returned only for the requested company
6.2 Show Role
Returns one role with permissions filtered bycompany_id.
Recommended Query Parameter
Example Request
- unlike the index endpoint,
show()does not explicitly validatecompany_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
labelis requireddescriptionis 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 usingsyncWithPivotValues().
Request JSON
- 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
- create role
- archive role
- unarchive role
- delete role
8.2 Company Context Matters
The same role object can show different permissions depending oncompany_id.
Always send:
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:
9. Recommended Postman Test Order
- Login as an admin or super-admin
- Call
GET /api/roles?company_id=1 - Call
GET /api/role/2?company_id=1 - Update a role description with
POST /api/role/{id} - Assign a complete permission list with
POST /api/role/{id}/assign_permissions - Re-fetch the role to confirm the permission pivot rows for that company