F
Filament4mo ago
Tarık

Fabricator With Multi-Tenancy

Hello, I trying create fabricator-admin panel page dynamicly. But When I switch multitenancy, my custom fabricator pages not working. My FabricatorTest class:
<?php

namespace App\Filament\Pages;

use Filament\Pages\Page;
use Filament\Navigation\NavigationItem;
use Z3d0X\FilamentFabricator\Models\Page as FabricatorPage;

class FabricatorTest extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static ?string $title = '';
protected static string $view = 'filament.pages.fabricator-test';
protected $page;

public function mount($slug): void
{
$this->page = FabricatorPage::where('slug', $slug)->firstOrFail();
self::$title = $this->page->title;
}

public static function getNavigationItems(): array
{
$pages = FabricatorPage::all();

return $pages->map(function ($page) {
$request = (object) request();
logger($request);


// $tenantId = $request->route('tenant_id');
return NavigationItem::make($page->title)
->url(route('filament.pages.fabricator-test', ['tenant' => filament()->getTenant(), 'slug' => $page->slug]))
->isActiveWhen(fn (): bool => $request->route('slug') === $page->slug)
->icon('heroicon-o-document');
})->toArray();
}

protected function getViewData(): array
{
return [
'page' => $this->page,
];
}
}
<?php

namespace App\Filament\Pages;

use Filament\Pages\Page;
use Filament\Navigation\NavigationItem;
use Z3d0X\FilamentFabricator\Models\Page as FabricatorPage;

class FabricatorTest extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static ?string $title = '';
protected static string $view = 'filament.pages.fabricator-test';
protected $page;

public function mount($slug): void
{
$this->page = FabricatorPage::where('slug', $slug)->firstOrFail();
self::$title = $this->page->title;
}

public static function getNavigationItems(): array
{
$pages = FabricatorPage::all();

return $pages->map(function ($page) {
$request = (object) request();
logger($request);


// $tenantId = $request->route('tenant_id');
return NavigationItem::make($page->title)
->url(route('filament.pages.fabricator-test', ['tenant' => filament()->getTenant(), 'slug' => $page->slug]))
->isActiveWhen(fn (): bool => $request->route('slug') === $page->slug)
->icon('heroicon-o-document');
})->toArray();
}

protected function getViewData(): array
{
return [
'page' => $this->page,
];
}
}
my router (web.php):
use App\Filament\Pages\FabricatorTest;

Route::get('admin/{tenant}/fabricator-test/{slug}', FabricatorTest::class)->name('filament.pages.fabricator-test');
use App\Filament\Pages\FabricatorTest;

Route::get('admin/{tenant}/fabricator-test/{slug}', FabricatorTest::class)->name('filament.pages.fabricator-test');
Error: Missing required parameter for [Route: filament.admin.pages.all-charts-page] [URI: admin/{tenant}/all-charts-page] [Missing parameter: tenant]. note: I dont try open 'all-chart-page'. I try fabricator-test page but another page throw error. Please help and I am newby here 👋 thank you
No description
3 Replies
Tarık
TarıkOP4mo ago
I updated code but still i got same error
Tarık
TarıkOP4mo ago
as you see, I sent "tenant" paramater from routing parameters
No description
Tarık
TarıkOP4mo ago
In FabricatorTest page Filament::getTenant() return null. problem solved.
Want results from more Discord servers?
Add your server