Skip to content

Commit

Permalink
Create CanDisableBadges.php
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Oct 29, 2024
1 parent c582927 commit 8f8ef12
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Concerns/CanDisableBadges.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace LaraZeus\FilamentPluginTools\Concerns;
use Closure;

trait CanDisableBadges
{
protected Closure | bool $showNavigationBadges = true;

protected array $showNavigationBadgesArray = [];

public function hideNavigationBadges(Closure | bool $show = false, ?string $resource = null): static
{
return $this->setShowNavigationBadges($show, $resource);
}

public function showNavigationBadges(Closure | bool $show = true, ?string $resource = null): static
{
return $this->setShowNavigationBadges($show, $resource);
}

private function setShowNavigationBadges(Closure | bool $show = true, ?string $resource = null): static
{
if ($resource !== null) {
$this->showNavigationBadgesArray[$resource] = $show;
} else {
$this->showNavigationBadges = $show;
}

return $this;
}

public function getShowNavigationBadges(string $resource = null): bool
{
if ($resource !== null) {
return $this->showNavigationBadgesArray[$resource] ?? $this->evaluate($this->showNavigationBadges);
}

return $this->evaluate($this->showNavigationBadges);
}

public static function getNavigationBadgesVisibility($resource = null): bool
{
return (new static)::get()->getShowNavigationBadges($resource);
}
}

0 comments on commit 8f8ef12

Please sign in to comment.