October\Rain\Database\Traits\Multisite
Overview
Multisite trait allows for site-based models, the database table should contain site_id and site_root_id keys
Protected Properties
protected bool $multisiteRelationsDefined
multisiteRelationsDefined prevents redundant processing during unserialization (__wakeup) since relation definitions persist through serialization.
Public Methods
public addPropagatable()
public addPropagatable(array|string|null $attributes = null): void
addPropagatable attributes for the model.
public static bootMultisite()
public static bootMultisite(): void
bootMultisite trait for a model.
public canDeleteMultisiteRelation()
public canDeleteMultisiteRelation($name, $type = null): bool
canDeleteMultisiteRelation checks if a relation has the potential to be shared with the current model. If there are 2 or more records in existence, then this method will prevent the cascading deletion of relations.
See Also
public deleteForSite()
public deleteForSite($siteId = null): void
deleteForSite runs the delete command on a model for another site, useful for cleaning up records for other sites when the parent is deleted.
public findForSite()
public findForSite($siteId = null): void
findForSite will locate a record for a specific site.
public findOrCreateForSite()
public findOrCreateForSite($siteId = null): void
public findOtherSiteModel()
public findOtherSiteModel($siteId = null): void
public getMultisiteConfig()
public getMultisiteConfig($key, $default = null): void
public getMultisiteKey()
public getMultisiteKey(): void
getMultisiteKey returns the root key if multisite is used
public getMultisiteSyncSites()
public getMultisiteSyncSites(): array
public getQualifiedSiteIdColumn()
public getQualifiedSiteIdColumn(): string
getQualifiedSiteIdColumn gets the fully qualified "site id" column.
public getSiteIdColumn()
public getSiteIdColumn(): string
getSiteIdColumn gets the name of the "site id" column.
public initializeMultisite()
public initializeMultisite(): void
public isAttributePropagatable()
public isAttributePropagatable($attribute): bool
public isMultisiteEnabled()
public isMultisiteEnabled(): bool
isMultisiteEnabled allows for programmatic toggling
public isMultisiteSyncEnabled()
public isMultisiteSyncEnabled(): void
public multisiteAfterCreate()
public multisiteAfterCreate(): void
multisiteAfterCreate constructor event used internally
public multisiteAfterDelete()
public multisiteAfterDelete(): void
public multisiteBeforeSave()
public multisiteBeforeSave(): void
multisiteBeforeSave constructor event used internally
public multisiteSaveComplete()
public multisiteSaveComplete(): void
multisiteSaveComplete constructor event used internally
public newOtherSiteQuery()
public newOtherSiteQuery(): void
public propagateToSite()
public propagateToSite($siteId, $otherModel = null): void
propagateToSite will save propagated fields to other records
public savePropagate()
public savePropagate($options = null, $sessionKey = null): bool
savePropagate the model, including to other sites
public scopeApplyOtherSiteRoot()
public scopeApplyOtherSiteRoot(
Illuminate\Database\Eloquent\Builder $query,
string|\Illuminate\Database\Eloquent\Model $idOrModel
): Illuminate\Database\Eloquent\Builder
scopeApplyOtherSiteRoot is used to resolve a model using its ID or its root ID. For example, finding a model using attributes from another site, or finding all connected models for all sites.
If the value is provided as a string, it must be the ID from the primary record,
in other words: taken from site_root_id not from the id column.
Protected Methods
protected defineMultisiteRelation()
protected defineMultisiteRelation($name, $type = null): void
defineMultisiteRelation will modify defined relations on this model so they share
their association using the shared identifier (site_root_id). Only these relation
types support relation sharing: belongsToMany, morphToMany, morphedByMany,
belongsTo, hasOne, hasMany, attachOne, attachMany.
For many-to-many relations where both parent AND related models use multisite (dual-multisite), the keys remain as default 'id' and propagation handles syncing the correct site-specific related records.
protected defineMultisiteRelations()
protected defineMultisiteRelations(): void
defineMultisiteRelations will spin over every relation and apply propagation config
protected isModelUsingSameSite()
protected isModelUsingSameSite($siteId = null): void
protected isRelatedMultisite()
protected isRelatedMultisite($name): bool
isRelatedMultisite checks if a related model class uses multisite. This checks that multisite is enabled via the MultisiteInterface.
protected propagateHasManyRelation()
protected propagateHasManyRelation($name, $siteId, $otherModel): void
propagateHasManyRelation syncs a hasMany relation with multisiteSync to another site. Each child model must use the Multisite trait. The child's own $propagatable controls which attributes are copied.
protected propagateManyToManyRelation()
protected propagateManyToManyRelation($name, $siteId, $otherModel): void
propagateManyToManyRelation propagates a many-to-many relation to another site. For dual-multisite (both models use multisite), this finds the corresponding related records in the target site and syncs them.