Skip to content

How to check if a new version created or not #95

@AhmedElTabarani

Description

@AhmedElTabarani

I need the best way to detect if a new version has been created or not

right now I do it like this

$currentVersion = $quotation->lastVersion()->first();

$this->updateQuotation($quotation, $data);

$newVersion = $quotation->lastVersion()->first();

if ($currentVersion->id != $newVersion->id) {
    // do something
}

But I think we can do it efficiently

I create a helper function for that

public function wasVersioned(): bool
{
    $versionableAttributes = $this->getVersionableAttributes($this->getVersionStrategy());
    return Arr::hasAny($this->getDirty(), array_keys($versionableAttributes));
}

and i used it like this

$this->updateQuotation($quotation, $data);

if ($quotation->wasVersioned()) {
    // do something
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions