• Reading time ~ 1 min
  • 14.08.2022

Version Control for Laravel is a package that provides database version control for Eloquent models. This package works by creating a separate *_versions database table that corresponds with the model (i.e., users_versions).

You start by extending the package's base model for models you'd like to include version control:

use Redsnapper\LaravelVersionControl\Models\BaseModel;
 
class Post extends BaseModel
{
}

Since two tables are required, you need to use the provided base Migration class to define migrations:

use Redsnapper\LaravelVersionControl\Database\Blueprint;
use Redsnapper\LaravelVersionControl\Database\Migration;
 
class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $this->makeVcTables("users",function(Blueprint $table){
            $table->string('email')->unique();
            $table->string('password');
        },function(Blueprint $table){
            $table->string('email');
            $table->string('password');
        });
    }
}

Finally, you can retrieve model versions using the versions() method on models that extend the base model in this package:

$model->versions();

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297