Skip to content
Permalink
Browse files

Add Synchronization model

  • Loading branch information
lorisleiva committed Sep 17, 2018
1 parent 76ee6b5 commit e8ffdb52d80b73a31bc924a915d26b1fcf801daa
@@ -0,0 +1,43 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Ramsey\Uuid\Uuid;

class Synchronization extends Model
{
public $incrementing = false;

protected $fillable = [
'token', 'last_synchronized_at'
];

protected $casts = [
'last_synchronized_at' => 'datetime',
];

public function ping()
{
return $this->synchronizable->synchronize();
}

public function synchronizable()
{
return $this->morphTo();
}

public static function boot()
{
parent::boot();

static::creating(function ($synchronization) {
$synchronization->id = Uuid::uuid4();
$synchronization->last_synchronized_at = now();
});

static::created(function ($synchronization) {
$synchronization->ping();
});
}
}
@@ -9,7 +9,8 @@
"fideloper/proxy": "^4.0",
"google/apiclient": "^2.2",
"laravel/framework": "5.6.*",
"laravel/tinker": "^1.0"
"laravel/tinker": "^1.0",
"ramsey/uuid": "^3.8"
},
"require-dev": {
"filp/whoops": "^2.0",

Some generated files are not rendered by default. Learn more.

@@ -0,0 +1,40 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSynchronizationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('synchronizations', function (Blueprint $table) {
$table->string('id');

// Relationships.
$table->morphs('synchronizable');

// Data.
$table->string('token')->nullable();

// Timestamps.
$table->datetime('last_synchronized_at');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('synchronizations');
}
}

0 comments on commit e8ffdb5

Please sign in to comment.