Target Class [cache] does not exist

I don't really know much about the core behaviour and what todo/not todo inside service providers What i am attempting to create is a simple session based "recently viewed" list of navigation items in the sidebar utilizing \Filament\Navigation\NavigationItem::make() on items visited See attached image Any panel requirements of core laravel features doesn't seem to work, like translations ( using a __('text') anywhere in labels doesn't resolve the translation and only results in a "Target Class [translator] does not exist"
use \Illuminate\Support\Facades\Session;

class AppPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
$recently_visited = Session::get('key', []);
use \Illuminate\Support\Facades\Session;

class AppPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
$recently_visited = Session::get('key', []);
results in a Illuminate\Contracts\Container\BindingResolutionException Target class [cache] does not exist. My providers array looks like this: ( config/app.php )
'providers' => ServiceProvider::defaultProviders()->merge([
/*
* Package Service Providers...
*/

/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\SparkServiceProvider::class,
App\Providers\HorizonServiceProvider::class,
App\Providers\Filament\AdminPanelProvider::class,
App\Providers\Filament\AppPanelProvider::class,
App\Providers\RouteServiceProvider::class,
])->toArray(),
'providers' => ServiceProvider::defaultProviders()->merge([
/*
* Package Service Providers...
*/

/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\SparkServiceProvider::class,
App\Providers\HorizonServiceProvider::class,
App\Providers\Filament\AdminPanelProvider::class,
App\Providers\Filament\AppPanelProvider::class,
App\Providers\RouteServiceProvider::class,
])->toArray(),
Is this intended behaviour of the panel service provider? Is it bad practice to use dynamic features in this way? not sure where to move the logic to get the same benefits Next option on my todo list is to move the Navigation items into a Page and use the getNavigationItems method to resolve it (https://filamentphp.com/docs/3.x/panels/navigation#registering-custom-navigation-items-1)
No description
4 Replies
WebKenth
WebKenthOP14mo ago
I was able to move my logic into a Page Although now the page is responsible for the entire "recently viewed" section of the navigation I added my logic to a Custom page and overwrote the: getNavigationItems function I kept the original Page NavigationItem and just added my own array afterwards Still need to clean it up abit, but no missing Cache class anymore 😛
/**
* @return array<NavigationItem>
*/
public static function getNavigationItems(): array
{
$navigationItems = [
\Filament\Navigation\NavigationItem::make(static::getNavigationLabel())
->group(static::getNavigationGroup())
->icon(static::getNavigationIcon())
->activeIcon(static::getActiveNavigationIcon())
->isActiveWhen(fn (): bool => request()->routeIs(static::getRouteName()))
->sort(static::getNavigationSort())
->badge(static::getNavigationBadge(), color: static::getNavigationBadgeColor())
->url(static::getNavigationUrl()),
];

$recently_viewed = session()->get('recently_visited', []);
foreach ($recently_viewed as $key => $item) {
$navigationItems[] = \Filament\Navigation\NavigationItem::make('dashboard_' . $key)
->label(fn (): string => $item['name'])
->url(fn (): string => '')
->group('Recently Viewed');
}
return $navigationItems;
}
/**
* @return array<NavigationItem>
*/
public static function getNavigationItems(): array
{
$navigationItems = [
\Filament\Navigation\NavigationItem::make(static::getNavigationLabel())
->group(static::getNavigationGroup())
->icon(static::getNavigationIcon())
->activeIcon(static::getActiveNavigationIcon())
->isActiveWhen(fn (): bool => request()->routeIs(static::getRouteName()))
->sort(static::getNavigationSort())
->badge(static::getNavigationBadge(), color: static::getNavigationBadgeColor())
->url(static::getNavigationUrl()),
];

$recently_viewed = session()->get('recently_visited', []);
foreach ($recently_viewed as $key => $item) {
$navigationItems[] = \Filament\Navigation\NavigationItem::make('dashboard_' . $key)
->label(fn (): string => $item['name'])
->url(fn (): string => '')
->group('Recently Viewed');
}
return $navigationItems;
}
Dennis Koch
Dennis Koch14mo ago
The issue was, that the method was probably executed through a service provider and the framework wasn’t booted yet
WebKenth
WebKenthOP14mo ago
Wondering how we can "fix" this the correct way I don't mind having the logic moved, but it seems like a bug not being able to do translations in a service provider when the panel's configuration is being set there
Dennis Koch
Dennis Koch14mo ago
Moving stuff in a closure instead of executing it directly in the method should be a solution
Want results from more Discord servers?
Add your server