1. Go to this page and download the library: Download anexia/laravel-changeset library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// base model class app/BaseModel.php
namespace App;
use Anexia\Changeset\Traits\ChangesetTrackable;
use Illuminate\Database\Eloquent\Model;
class BaseModel extends Model
{
use ChangesetTrackable;
// possible other "global" behaviour for all models can be put here
}
----------------------------------
// actual model class app/Post.php
namespace App;
class Post extends BaseModel
{
protected $table = 'posts';
protected $fillable = ['author_id', 'name', 'content'];
protected $trackBy = 'id';
protected $trackFields = ['author_id', 'name', 'content'];
protected $tackRelated = ['author' => 'posts'];
public function author()
{
return $this->belongsTo('App\User', 'author_id');
}
}
----------------------------------
// actual model class app/User.php
namespace App;
class User extends BaseModel implements ChangesetUserInterface
{
protected $table = 'users';
protected $fillable = ['name', 'email'];
protected $trackBy = 'id';
protected $trackFields = ['name', 'email'];
/**
* Implementation of
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder {
public function run()
{
Model::unguard();
// Changeset Seeds (ObjectType)
$this->call(\Anexia\Changeset\Database\Seeds\ChangesetObjectTypeSeeder::class);
$this->command->info('Changeset object types seeded!');
// other seeds
$this->call('AnotherSeeder');
$this->command->info('Other data seeded!');
...
}
}
php artisan db:seed
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.