Skip to content

Commit

Permalink
Merge pull request #41 from tipoff/omnia/feature/25-add-update-models…
Browse files Browse the repository at this point in the history
…-result-ranking

Omnia/feature/25 add update models result ranking
  • Loading branch information
drewroberts authored Mar 5, 2021
2 parents 035ee5e + ac7a544 commit 3b454a1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public function up()
$table->string('type')->index(); // Example: 'Organic', 'Local', 'Ads', 'Inline Video'
$table->unsignedTinyInteger('position')->index();

// Result (one or the other)
$table->foreignIdFor(Webpage::class)->nullable();
$table->foreignIdFor(Place::class)->nullable();
// resultable_id, resultable_type either Tipoff\Seo\Models\Webpage or Place
$table->morphs('resultable');

// Don't need timestamps since can use created_at timestamp of the ranking class

Expand Down
5 changes: 5 additions & 0 deletions src/Models/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ class Place extends BaseModel
use HasPackageFactory;
use HasCreator;
use HasUpdater;

public function results()
{
return $this->morphMany(Result::class, 'resultable');
}
}
9 changes: 2 additions & 7 deletions src/Models/Ranking.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ class Ranking extends BaseModel
use HasCreator;
use HasUpdater;

public function webpage()
public function results()
{
return $this->belongsTo(app('webpage'));
}

public function places()
{
return $this->belongsTo(app('place'));
return $this->hasMany(Result::class);
}
}
27 changes: 27 additions & 0 deletions src/Models/Result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Tipoff\Seo\Models;

use Tipoff\Support\Models\BaseModel;
use Tipoff\Support\Traits\HasCreator;
use Tipoff\Support\Traits\HasPackageFactory;
use Tipoff\Support\Traits\HasUpdater;

class Result extends BaseModel
{
use HasPackageFactory;
use HasCreator;
use HasUpdater;

public function ranking()
{
return $this->belongsTo(Ranking::class);
}

public function resultable()
{
return $this->morphTo();
}
}
8 changes: 4 additions & 4 deletions src/Models/Webpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class Webpage extends BaseModel
use HasCreator;
use HasUpdater;

public function domain()
public function results()
{
return $this->belongsTo(app('domain'));
return $this->morphMany(Result::class, 'resultable');
}

public function rankings()
public function domain()
{
return $this->hasMany(app('ranking'));
return $this->belongsTo(app('domain'));
}
}

0 comments on commit 3b454a1

Please sign in to comment.