Skip to content

Relationship Repository Traits ​

These traits handle the repository-side persistence and form hydration for assignment, authorization, and creator tracking features. They pair with the corresponding Entity Traits (Assignable, HasAuthorizable, HasCreator).


AssignmentTrait ​

Namespace: Unusualify\Modularous\Repositories\Traits\AssignmentTrait

Manages assignment-related form field hydration, default query filtering, and data table filter tabs. Uses the Allowable trait internally for role-based permission checks on filter visibility.

Properties ​

PropertyTypeDescription
$hasUserAwareCacheAssignmentTraitboolSignals the cache layer that this trait produces user-specific results

Lifecycle Hooks ​

HookDescription
setColumnsAssignmentTraitRegisters inputs matching type: assignment
getFormFieldsAssignmentTraitSets each assignment column to the model's primary key
filterAssignmentTraitApplies everAssignedToYourRoleOrHasAuthorization scope to index queries

Table Filters ​

getTableFiltersAssignmentTrait() returns filter tabs for the data table:

FilterSlugScope
My Assignmentsmy-assignmentsisActiveAssignee
Your Role Assignmentsyour-role-assignmentsisActiveAssigneeForYourRole
Completed Assignmentscompleted-assignmentscompletedAssignments
Pending Assignmentspending-assignmentspendingAssignments
Your Completed Assignmentsyour-completed-assignmentsyourCompletedAssignments
Team Completed Assignmentsteam-completed-assignmentsteamCompletedAssignments
Your Pending Assignmentsyour-pending-assignmentsyourPendingAssignments
Team Pending Assignmentsteam-pending-assignmentsteamPendingAssignments

INFO

The "Completed Assignments" and "Pending Assignments" tabs are only visible to users with superadmin, admin, or manager roles (checked via Allowable).

Methods ​

MethodSignatureDescription
getAssignments(mixed $id): CollectionReturns all Assignment records for a given model ID, ordered by created_at desc

Usage ​

php
use Unusualify\Modularous\Repositories\Traits\AssignmentTrait;

class TaskRepository extends Repository
{
    use AssignmentTrait;
}

$repo->getAssignments($taskId);

AuthorizableTrait ​

Namespace: Unusualify\Modularous\Repositories\Traits\AuthorizableTrait

Hydrates authorization record data into form fields and provides authorized/unauthorized filter tabs.

Lifecycle Hooks ​

HookDescription
getFormFieldsAuthorizableTraitIf the model has an existing authorization record, populates authorized_id and authorized_type into form fields. Casts authorized_id to integer when the authorized model does not use UUIDs.

Table Filters ​

getTableFiltersAuthorizableTrait() returns:

FilterSlugScopeCondition
AuthorizedauthorizedhasAnyAuthorizationOnly if model hasAuthorizationUsage()
UnauthorizedunauthorizedunauthorizedOnly if model hasAuthorizationUsage()
Your Authorizationsyour-authorizationsisAuthorizedToYouAlways shown

Usage ​

php
use Unusualify\Modularous\Repositories\Traits\AuthorizableTrait;

class ReportRepository extends Repository
{
    use AuthorizableTrait;
}

CreatorTrait ​

Namespace: Unusualify\Modularous\Repositories\Traits\CreatorTrait

Applies creator-based access scoping on index queries, hydrates the custom_creator_id form field, and prepends a creator input to the form schema.

Properties ​

PropertyTypeDescription
$hasUserAwareCacheCreatorTraitboolSignals the cache layer that results depend on the current user

Lifecycle Hooks ​

HookDescription
filterCreatorTraitAdds hasAccessToCreation scope to limit results to the user's own records (or authorized records)
getFormFieldsCreatorTraitPopulates custom_creator_id from the model's creator relation when the schema defines it
prependFormSchemaCreatorTraitPrepends a type: creator input to the form schema, displaying the creator info at the top of forms

Usage ​

php
use Unusualify\Modularous\Repositories\Traits\CreatorTrait;

class ArticleRepository extends Repository
{
    use CreatorTrait;
}

// Index queries automatically filter by creator access
// Form fields include the creator display