• Czas czytania ~1 min
  • 10.07.2022

Kontrola wersji dla Laravel to pakiet, który zapewnia kontrolę wersji bazy danych dla modeli Eloquent. Ten pakiet działa poprzez utworzenie oddzielnej tabeli bazy danych *_versions, która odpowiada modelowi (tj. users_versions).

Zaczynasz od rozszerzenia podstawowego modelu pakietu o modele, które chcesz uwzględnić w kontroli wersji:

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

Ponieważ wymagane są dwie tabele, do zdefiniowania migracji należy użyć dostarczonej podstawowej klasy Migration:

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');
        });
    }
}

Na koniec możesz pobrać wersje modelu za pomocą metody versions() w modelach, które rozszerzają model podstawowy w tym pakiecie:

$model->versions();

Możesz się nauczyćwięcej o tym pakiecie, uzyskaj pełne instrukcje instalacji i zobacz kod źródłowy na GitHub.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

O

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...

O autorze CrazyBoy49z
WORK EXPERIENCE
Kontakt
Ukraine, Lutsk
+380979856297