Skip to content

Repository Logic Traits ​

Repository traits extend the base Repository class with domain-specific persistence logic. While Entity Traits define model-level behavior (relationships, scopes, accessors), repository traits handle how data flows in and out — form field hydration, after-save side effects, column detection, table filters, and caching.

Every repository trait follows a naming convention that the base Repository automatically discovers and invokes at the correct lifecycle stage:

ConventionSignatureWhen Called
setColumns{Trait}($columns, $inputs): arrayDuring boot — registers which form input names this trait manages
prepareFieldsBeforeCreate{Trait}($fields): arrayBefore a new record is inserted
prepareFieldsBeforeSave{Trait}($object, $fields): arrayBefore any save (create or update)
beforeSave{Trait}($object, $fields): voidJust before the Eloquent save() call
afterSave{Trait}($object, $fields): voidImmediately after save() — side effects (pivot syncing, file moves, etc.)
hydrate{Trait}($object, $fields): ModelSets in-memory relationships before save (preview/validation)
getFormFields{Trait}($object, $fields, $schema): arrayPopulates form fields when editing an existing record
afterDelete{Trait}($object): voidCleanup after soft-delete
afterRestore{Trait}($object): voidRestoration hook
filter{Trait}($query, &$scopes): voidApplies default query scopes/filters on index listings
order{Trait}($query, &$orders): voidApplies ordering logic
getTableFilters{Trait}($scope): arrayReturns filter tab definitions for the data table UI
getFormActions{Trait}($scope): arrayReturns form action button definitions

Trait Groups ​

GroupNamespacePurpose
MediaRepositories\Traits\Persist files, images, and Filepond uploads
RelationshipsRepositories\Traits\Save assignment, authorization, and creator data
ContentRepositories\Traits\Slugs, translations, tags, and spreadable JSON
StateRepositories\Traits\State machine filter lists and table filters
PaymentRepositories\Traits\Price and payment record management
ProcessesRepositories\Traits\Workflow processes and repeater blocks
OAuthRepositories\Traits\Social login user lookup and creation
LogicRepositories\Logic\Caching layer and trait introspection

Media Traits ​

TraitPageSummary
FilepondsTraitMedia →Persists Filepond temporary uploads to permanent storage after save
FilesTraitMedia →Syncs File model attachments through the fileables pivot
ImagesTraitMedia →Syncs Media model attachments through the mediables pivot

Relationship Traits ​

TraitPageSummary
AssignmentTraitRelationships →Provides assignment form fields, default filters, and table filter tabs
AuthorizableTraitRelationships →Hydrates authorization record fields and adds authorized/unauthorized filters
CreatorTraitRelationships →Applies creator-based access scope and prepends creator form input

Content Traits ​

TraitPageSummary
SlugsTraitContent →Persists locale-aware slugs and resolves slug-based lookups
SpreadableTraitContent →Moves spreadable fields into/from the JSON Spread record
TagsTraitContent →Syncs tags (with locale support) and provides tag query helpers
TranslationsTraitContent →Prepares per-locale translation fields and handles translatable search/ordering

State Traits ​

TraitPageSummary
StateableTraitState →Builds state filter lists and table filter tabs from the model's state machine

Payment Traits ​

TraitPageSummary
PricesTraitPayment →Creates, updates, and deletes morphed Price records with currency exchange
PaymentTraitPayment →Orchestrates payment price calculation, payment service integration, and pay action

Process Traits ​

TraitPageSummary
ProcessableTraitProcesses →Auto-creates workflow processes and hydrates process form fields
RepeatersTraitProcesses →Persists nested repeater JSON blocks with locale and media support

OAuth Traits ​

TraitPageSummary
OauthTraitOAuth →Looks up, links, and creates users from OAuth provider data

Logic Traits ​

TraitPageSummary
QueryBuilderLogic/QueryBuilder →Paginated listing, single-record lookup, multi-ID fetching, and flat-list helpers
MethodTransformersLogic/MethodTransformers →Lifecycle hook dispatcher — fans out to every {hookName}{Trait} method across loaded traits
RelationshipsLogic/Relationships →Syncs all Eloquent relationship types (BelongsToMany, HasMany, MorphMany, MorphTo, MorphToMany) on save
RelationshipHelpersLogic/RelationshipHelpers →Reflection-based relationship discovery and foreign key resolution
SchemaLogic/Schema →Active schema management and input chunking helpers
CountBuildersLogic/CountBuilders →Cached aggregate counts for status tabs (all, published, draft, trash)
DatesLogic/Dates →Normalises date fields to Y-m-d H:i:s before save
DispatchEventsLogic/DispatchEvents →Dispatches domain events (create/update/delete/restore) after database commit
CollationSelectorLogic/CollationSelector →Applies explicit MySQL collation to LIKE search queries on text columns
CacheableTraitLogic/CacheableTrait →Relationship-aware caching for index and record queries
InspectTraitsLogic/InspectTraits →Runtime introspection — checks whether repository or model uses a given trait
TouchableEloquentModelLogic/TouchableEloquentModel →Deferred updated_at touching — fires exactly once after all relationship syncs