Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omnia/feature/25 add update models result ranking #41

Merged
merged 6 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
}
}