Skip to content

Commit

Permalink
Merge pull request #2 from lara-zeus/can-disable-badges
Browse files Browse the repository at this point in the history
Create CanDisableBadges.php
  • Loading branch information
atmonshi authored Oct 29, 2024
2 parents c582927 + c3000ea commit fd0a9f9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Concerns/CanDisableBadges.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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 fd0a9f9

Please sign in to comment.