Skip to content

Commit

Permalink
allow to show/hide badges
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Oct 29, 2024
1 parent 7057176 commit 77318dc
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 402 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"doctrine/dbal": "^3.5.1",
"filament/spatie-laravel-media-library-plugin": "^3.0",
"filament/spatie-laravel-tags-plugin": "^3.0",
"lara-zeus/core": "^3.1",
"lara-zeus/filament-plugin-tools": "^1.0",
"spatie/laravel-medialibrary": "^11.0",
"spatie/laravel-sluggable": "^3.3",
"spatie/laravel-tags": "^4.6",
"lara-zeus/core": "^3.1"
"spatie/laravel-tags": "^4.6"
},
"require-dev": {
"phpunit/phpunit": "^10.1",
Expand Down
880 changes: 480 additions & 400 deletions composer.lock

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions docs/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ SkyPlugin::make()
->hideResources([
FaqResource::class,
])

// hide/show nav badges
->hideNavigationBadges(resource: LaraZeus\Sky\Resources::CollectionResource)
->showNavigationBadges(resource: LaraZeus\Sky\Resources::CollectionResource)

```

## Customize Filament Resources
Expand All @@ -66,6 +71,30 @@ PostResource::navigationIcon('heroicon-o-home');
PostResource::navigationGroup('New Name');
```


### Show or Hide Badges

To show all navigation badges (default)
```
->showNavigationBadges()
```

To hide all navigation badges
```
->hideNavigationBadges()
```

This will hide only the CollectionResource navigation badge
```
->hideNavigationBadges(resource: LaraZeus\Sky\Resources::CollectionResource)
```

This will show only the FormResource navigation badge
```
->hideNavigationBadges()
->showNavigationBadges(resource: LaraZeus\Sky\Resources::CollectionResource)
```

available resources:

- FaqResource,
Expand Down
4 changes: 4 additions & 0 deletions src/Filament/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ public static function getNavigationLabel(): string

public static function getNavigationBadge(): ?string
{
if (! SkyPlugin::getNavigationBadgesVisibility(static::class)) {
return null;
}

return (string) SkyPlugin::get()->getModel('Post')::page()->count();
}

Expand Down
4 changes: 4 additions & 0 deletions src/Filament/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ public static function getNavigationLabel(): string

public static function getNavigationBadge(): ?string
{
if (! SkyPlugin::getNavigationBadgesVisibility(static::class)) {
return null;
}

return (string) SkyPlugin::get()->getModel('Post')::posts()->count();
}

Expand Down
4 changes: 4 additions & 0 deletions src/Filament/Resources/SkyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public static function shouldRegisterNavigation(): bool

public static function getNavigationBadge(): ?string
{
if (! SkyPlugin::getNavigationBadgesVisibility(static::class)) {
return null;
}

return (string) static::getModel()::query()->count();
}
}
2 changes: 2 additions & 0 deletions src/SkyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Filament\Panel;
use Filament\Support\Concerns\EvaluatesClosures;
use LaraZeus\Core\Concerns\HasRouteNamePrefix;
use LaraZeus\FilamentPluginTools\Concerns\CanDisableBadges;
use LaraZeus\Sky\Filament\Resources\FaqResource;
use LaraZeus\Sky\Filament\Resources\LibraryResource;
use LaraZeus\Sky\Filament\Resources\NavigationResource;
Expand All @@ -15,6 +16,7 @@

final class SkyPlugin implements Plugin
{
use CanDisableBadges;
use Configuration;
use EvaluatesClosures;
use HasRouteNamePrefix;
Expand Down

0 comments on commit 77318dc

Please sign in to comment.