ntpscrt
ntpscrt
FFilament
Created by ntpscrt on 9/6/2023 in #❓┊help
CORS Problem with FileUpload on different server
No description
2 replies
FFilament
Created by ntpscrt on 8/21/2023 in #❓┊help
Does spatie-laravel-settings-plugin support tenant ?
I couldn't find any resource related to tenant
2 replies
FFilament
Created by ntpscrt on 8/13/2023 in #❓┊help
How to generate NavigationItem from DB ?
I would like to make custom Navigation by using Eloquent model, It works in V2 with these code.
AppServiceProvider.php
...
public function boot()
{
Filament::serving(function () {
$menus = Menu::all()
->map(function ($menu) {
return NavigationItem::make($menu->title)
->url($menu->filamentResourceUrl)
->icon($menu->filamentResourceIcon)
->isActiveWhen(fn (): bool => request('menu') == $menu->id)
->group($menu->filamentResourceMenuGroupLabel);
// ->sort(3);
});

Filament::registerNavigationItems([
...$menus->toArray(),
]);
});
}
...
AppServiceProvider.php
...
public function boot()
{
Filament::serving(function () {
$menus = Menu::all()
->map(function ($menu) {
return NavigationItem::make($menu->title)
->url($menu->filamentResourceUrl)
->icon($menu->filamentResourceIcon)
->isActiveWhen(fn (): bool => request('menu') == $menu->id)
->group($menu->filamentResourceMenuGroupLabel);
// ->sort(3);
});

Filament::registerNavigationItems([
...$menus->toArray(),
]);
});
}
...
In V3, I can't call any db query here and i have no idea where it should be.
Call to a member function connection() on null
Call to a member function connection() on null
https://flareapp.io/share/DPybYXD7#context-context-versions
class AdminPanelProvider extends PanelProvider
{

public function panel(Panel $panel): Panel
{
return $panel
...
->navigationItems($this->populateNavigationItems())
}



private function populateNavigationItems()
{
return Menu::all()
->map(function ($menu) {

return NavigationItem::make($menu->title)
->url(fn () => PostResource::getUrl(name: 'index', parameters: ['menu_id' => $menu->id]))
->icon('heroicon-o-newspaper')
->group('ข่าวสาร')
->sort(3);
})
->filter(fn ($menu) => !is_null($menu))
->toArray();
}
}
class AdminPanelProvider extends PanelProvider
{

public function panel(Panel $panel): Panel
{
return $panel
...
->navigationItems($this->populateNavigationItems())
}



private function populateNavigationItems()
{
return Menu::all()
->map(function ($menu) {

return NavigationItem::make($menu->title)
->url(fn () => PostResource::getUrl(name: 'index', parameters: ['menu_id' => $menu->id]))
->icon('heroicon-o-newspaper')
->group('ข่าวสาร')
->sort(3);
})
->filter(fn ($menu) => !is_null($menu))
->toArray();
}
}
Any ideas ?
4 replies