Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to show/hide badges #218

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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