F
Filamentβ€’2mo ago
MacTavish

"There are no commands defined in the "icons" namespace." when called via Widget Class

I have created a custom widget to execute some commands like sitemap generation, build caches, nuke caches. However, I am getting a namespace error. I have tried referencing command class in Artisan::call() but it didn't help. Here's my code
public function buildCaches() : int
{
$exitCode = Artisan::call('filament:optimize');
return $exitCode;
}

public function nukeCaches() : int
{
$exitCode = Artisan::call('filament:optimize-clear');
return $exitCode;
}
public function buildCaches() : int
{
$exitCode = Artisan::call('filament:optimize');
return $exitCode;
}

public function nukeCaches() : int
{
$exitCode = Artisan::call('filament:optimize-clear');
return $exitCode;
}
Solution:
there is a condition for these commands its only run on console: if ($this->app->runningInConsole()) so you'll need to register the command manually in app.php...
Jump to solution
12 Replies
MacTavish
MacTavishOPβ€’2mo ago
This seems to be problem with icon commands (caching & clearing), icons:cache called within filament:optimize & icons:clear called within filament:optimize-clear.
Solution
Lara Zeus
Lara Zeusβ€’2mo ago
there is a condition for these commands its only run on console: if ($this->app->runningInConsole()) so you'll need to register the command manually in app.php
->withCommands([
\BladeUI\Icons\Console\CacheCommand::class,
\BladeUI\Icons\Console\ClearCommand::class,
])
->withCommands([
\BladeUI\Icons\Console\CacheCommand::class,
\BladeUI\Icons\Console\ClearCommand::class,
])
MacTavish
MacTavishOPβ€’2mo ago
hmmm... Why are they made to be run in console only?
Lara Zeus
Lara Zeusβ€’2mo ago
dont know πŸ™‚ just checked the code and saw that
MacTavish
MacTavishOPβ€’2mo ago
Thank you. It worked
MacTavish
MacTavishOPβ€’2mo ago
However, Another problem is running laravel offered optimize command. Request takes very long time and when response is received, it breaks the page. Page is not interactble anymore. Trying to click buttons show error in console:
livewire.js?id=cc800bf4:4559 Uncaught TypeError: Cannot convert undefined or null to object
at Function.values (<anonymous>)
at get children (livewire.js?id=cc800bf4:4559:29)
at getDeepChildren (livewire.js?id=cc800bf4:9066:15)
at getDeepChildrenWithBindings (livewire.js?id=cc800bf4:9049:5)
at livewire.js?id=cc800bf4:9008:7
at Set.forEach (<anonymous>)
at Array.<anonymous> (livewire.js?id=cc800bf4:9006:13)
at trigger2 (livewire.js?id=cc800bf4:3940:34)
at CommitBus.createAndSendNewPool (livewire.js?id=cc800bf4:4178:7)
at livewire.js?id=cc800bf4:4158:16
livewire.js?id=cc800bf4:4559 Uncaught TypeError: Cannot convert undefined or null to object
at Function.values (<anonymous>)
at get children (livewire.js?id=cc800bf4:4559:29)
at getDeepChildren (livewire.js?id=cc800bf4:9066:15)
at getDeepChildrenWithBindings (livewire.js?id=cc800bf4:9049:5)
at livewire.js?id=cc800bf4:9008:7
at Set.forEach (<anonymous>)
at Array.<anonymous> (livewire.js?id=cc800bf4:9006:13)
at trigger2 (livewire.js?id=cc800bf4:3940:34)
at CommitBus.createAndSendNewPool (livewire.js?id=cc800bf4:4178:7)
at livewire.js?id=cc800bf4:4158:16
I have singled out the commands and it seems view:cache & config:cache are the one which cause the problem. My guess is that trying to build the caches invalidates current page and hence causes problem.
Lara Zeus
Lara Zeusβ€’2mo ago
are you running these command from a the browser?
MacTavish
MacTavishOPβ€’2mo ago
Yes. From a filament widget.
Lara Zeus
Lara Zeusβ€’2mo ago
I guess that can make some errors, if you refresh the page it will work fine without errors right? dont understand why you want the end user to run these commands kinda dangers, it should be run with the deployment
MacTavish
MacTavishOPβ€’2mo ago
Yes, If page is refreshed, it works fine. It's an admin panel where we know what we are doing it. It's just in case thing. I've done that previously for nova and custom pages of a custom backend. Sometimes we do change some cached stuff and we need to clear and rebuild cache at those times.
Lara Zeus
Lara Zeusβ€’2mo ago
I understand the need to flush some cache, but cacheing the views, config, icons, kinda high level to be done, these will affect all active sessions just my thoughts on the subject, I am sure you know what you're doing πŸ™‚ you can refresh the page after running the action.
MacTavish
MacTavishOPβ€’2mo ago
Caching has destroyed me more than relationships... So I tend to clear all cache & rebuild all! I've checked the exit code and it's 0. So it seems like my guess is correct, page needs to be refreshed after the action is done. Redirect not working after caching 🀣 . It just breaks everything after cache. No redirect, notifications, events work normally. Seems like I'll have to bother manually.
Want results from more Discord servers?
Add your server