Skip to content

Commit

Permalink
Make the layout options avilable static, as they should not change pe…
Browse files Browse the repository at this point in the history
…r model
  • Loading branch information
Kurt Friars committed Nov 22, 2023
1 parent c973f8e commit 9ea93ac
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/Concerns/HasLayouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public static function indexLayout(): Layout
return $layout;
}

public function layouts(): Collection
public static function layouts(): Collection
{
$layoutModel = static::layoutModel();

return $layoutModel::query()
->where($layoutModel::getLayoutableColumn(), static::layoutKey())
->when($this->globalLayouts(), function (Builder $query) use ($layoutModel) {
->when(static::globalLayouts(), function (Builder $query) use ($layoutModel) {
$query->orWhere(function (Builder $query) use ($layoutModel) {
$query->where($layoutModel::getTypeColumn(), LayoutType::Global)
->whereNotIn($layoutModel::getLayoutKeyColumn(), $this->excludedLayouts());
->whereNotIn($layoutModel::getLayoutKeyColumn(), static::excludedLayouts());
});
})
->get()
Expand Down Expand Up @@ -146,10 +146,10 @@ protected static function layoutModel(): string
/**
* Determine if the Layoutable uses global layouts
*/
protected function globalLayouts(): bool
protected static function globalLayouts(): bool
{
if (property_exists($this, 'globalLayouts')) {
return $this->globalLayouts;
if (property_exists(static::class, 'globalLayouts')) {
return static::$globalLayouts;
}

return true;
Expand All @@ -158,10 +158,10 @@ protected function globalLayouts(): bool
/**
* Exclude specific layouts by their keys
*/
protected function excludedLayouts(): array
protected static function excludedLayouts(): array
{
if (property_exists($this, 'excludedLayouts')) {
return $this->excludedLayouts;
if (property_exists(static::class, 'excludedLayouts')) {
return static::$excludedLayouts;
}

return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Layoutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function indexLayout(): Layout;
*
* @return Collection<Layout>
*/
public function layouts(): Collection;
public static function layouts(): Collection;

/**
* Define the key which is used to identify the Index layout for the Layoutable
Expand Down
2 changes: 1 addition & 1 deletion tests/Helper/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Page extends Model implements Contentable, Layoutable

protected $guarded = ['id'];

protected array $excludedLayouts = [
protected static array $excludedLayouts = [
'holidays',
];
}
2 changes: 1 addition & 1 deletion tests/Helper/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ class Post extends Model implements Contentable, Layoutable

protected $guarded = ['id'];

protected bool $globalLayouts = false;
protected static bool $globalLayouts = false;
}

0 comments on commit 9ea93ac

Please sign in to comment.