Skip to content

Commit

Permalink
Add table aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Ribeiro authored and ifox committed Jul 27, 2021
1 parent 14f7212 commit 1d98f3b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ protected function isTranslationModel()

public function scopePublished($query)
{
return $query->wherePublished(true);
return $query->where("{$this->getTable()}.published", true);
}

public function scopePublishedInListings($query)
{
if ($this->isFillable('public')) {
$query->wherePublic(true);
$query->where("{$this->getTable()}.public", true);

}

return $query->published()->visible();
Expand All @@ -42,12 +43,12 @@ public function scopeVisible($query)
{
if ($this->isFillable('publish_start_date')) {
$query->where(function ($query) {
$query->whereNull('publish_start_date')->orWhere('publish_start_date', '<=', Carbon::now());
$query->whereNull("{$this->getTable()}.publish_start_date")->orWhere("{$this->getTable()}.publish_start_date", '<=', Carbon::now());
});

if ($this->isFillable('publish_end_date')) {
$query->where(function ($query) {
$query->whereNull('publish_end_date')->orWhere('publish_end_date', '>=', Carbon::now());
$query->whereNull("{$this->getTable()}.publish_end_date")->orWhere("{$this->getTable()}.publish_end_date", '>=', Carbon::now());
});
}
}
Expand All @@ -62,12 +63,12 @@ public function setPublishStartDateAttribute($value)

public function scopeDraft($query)
{
return $query->wherePublished(false);
return $query->where("{$this->getTable()}.published", false);
}

public function scopeOnlyTrashed($query)
{
return $query->whereNotNull('deleted_at');
return $query->whereNotNull("{$this->getTable()}.deleted_at");
}

public function getFillable()
Expand Down

0 comments on commit 1d98f3b

Please sign in to comment.