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.