Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple version save logic into separate method #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mirzazeyrek
Copy link

Thank you for the great work on the package!

I have integrated into an existing project and noticed a functionality we need was missing. So introducing saveVersion model for forcing to create a version without any changes.

Example use case through a migration:


<?php

use App\Models\CustomerDocument;
use Illuminate\Database\Migrations\Migration;

class CreateVersionsForDocuments extends Migration
{
    public const REASON = 'MIGRATION';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $customerDocuments = CustomerDocument::all();
        foreach($customerDocuments as $customerDocument) {
            if(!$customerDocument->currentVersion()) {
                $customerDocument->setReasonAttribute(self::REASON);
                $customerDocument->saveVersion();
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant