Skip to main content

RolePathResource

Transforms a closure-table RolePath row into JSON. Used when RoleResource includes loaded paths.

Namespace

JobMetric\Rolix\Http\Resources\RolePathResource

Overview

Each path row links a role to an ancestor (or itself at level = 0) within a role type. The optional nested path object is the ancestor Role summary when the path relation is loaded.

Resource Structure

{
"type": "system",
"role_id": 2,
"path_id": 1,
"level": 1,
"path": {
"id": 1,
"name": "Administrator",
"type": "system"
}
}

Self path (level 0) typically has no nested path unless the relation was eager-loaded onto that row:

{
"type": "system",
"role_id": 2,
"path_id": 2,
"level": 0
}

Field Details

Complete Field Reference

FieldTypeAlways presentDescriptionExample
typestringyesRole type of the path namespace"system"
role_idintegeryesDescendant role id2
path_idintegeryesAncestor (or self) role id1
levelintegeryesDistance (0 = self)1
pathobjectwhenLoadedCompact ancestor rolesee below

whenLoaded Relations

JSON keyRelationShape
pathpath{ id, name, type } (not a full RoleResource)

Basic Usage

use JobMetric\Rolix\Models\RolePath;
use JobMetric\Rolix\Http\Resources\RolePathResource;

$paths = RolePath::query()
->where('role_id', 2)
->with('path')
->orderBy('level')
->get();

return RolePathResource::collection($paths);

Usually consumed via RoleResource with Role::with('paths.path').