Skip to content

Commit

Permalink
Add another layer of wrapping and correctly set on draftAllowedQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurt Friars committed Mar 10, 2024
1 parent 1a1b963 commit 5e00dd0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Concerns/QueriesPublishableModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'

protected function draftAllowedQuery($query, $column, $operator = null, $value = null, $boolean = 'and')
{
return $query->where(fn ($query) => $query->where(fn ($query) => $this->publishedWhere($query, $column, $operator, $value, $boolean))
->orWhere(fn ($query) => $this->unpublishedWhere($query, $column, $operator, $value, $boolean))
return $query->where(fn ($query) => $query->where(fn ($query) => $this->publishedWhere($query, $column, $operator, $value))
->orWhere(fn ($query) => $this->unpublishedWhere($query, $column, $operator, $value)), null, null, $boolean
);
}

protected function publishedWhere($query, $column, $operator = null, $value = null, $boolean = 'and')
protected function publishedWhere($query, $column, $operator = null, $value = null)
{
return $query->where($this->model->workflowColumn(), $this->model->publishedState())
->where($column, $operator, $value, $boolean);
->where($column, $operator, $value, 'and');
}

protected function unpublishedWhere($query, $column, $operator = null, $value = null, $boolean = 'and')
protected function unpublishedWhere($query, $column, $operator = null, $value = null)
{
return $query->whereNot($this->model->workflowColumn(), $this->model->publishedState())
->where($this->model->draftColumn().'->'.$column, $operator, $value, $boolean);
->where($this->model->draftColumn().'->'.$column, $operator, $value, 'and');
}

protected function shouldUseDraftColumn(string $column): bool
Expand Down

0 comments on commit 5e00dd0

Please sign in to comment.