Skip to content

Core\ChangeRelationships ​

Namespace: Unusualify\Modularous\Entities\Traits\Core\ChangeRelationships

Lightweight change-tracking for Eloquent relationships during a single request cycle. Used internally by HasFileponds and Core\ModelHelpers to flag which relationship collections changed so event listeners can react without re-querying.


Properties ​

PropertyTypeDescription
$changedRelationshipsarrayMap of relationship name → changed records

Methods ​

MethodSignatureDescription
setChangedRelationships(array $relationships): voidReplaces the entire changed-relationships map
addChangedRelationships(string $name, mixed $relationship): voidAdds a single relationship entry
mergeChangedRelationships(string $name, Collection $relationships): voidMerges new records into an existing entry
getChangedRelationships(): arrayReturns the full map
wasChangedRelationships(string|array|null $relationships = null): boolReturns true if any (or the specified) relationship changed

Usage ​

php
use Unusualify\Modularous\Entities\Traits\Core\ChangeRelationships;

class Article extends Model
{
    use ChangeRelationships;
}

// Mark a relationship as changed
$article->addChangedRelationships('images', $newImages);
$article->mergeChangedRelationships('images', $additionalImages);

// Check in a listener
if ($article->wasChangedRelationships()) {
    // some relationship changed
}

if ($article->wasChangedRelationships('images')) {
    // images specifically changed
}

if ($article->wasChangedRelationships(['images', 'files'])) {
    // images OR files changed
}