Panel Path as {brand} prefix Parameter

I have two panels: one is the default admin panel and the second is the brand panel. In the brand panel, I have defined the path as ->path('{brand_name}') In the route file, if I put Route::get('test', function () { return view('test'); }); it will give me a 404 Not Found error. This is because it will consider this route as part of the brand panel due to the defined prefix.
Solution:
$this->app->booting(function () { $this->loadRoutesFrom(base_path('./routes/') . "web.php"); }); This code worked for me. In the AppServiceProvider, I needed to load the Laravel route file before the package routes are loaded...
Jump to solution
4 Replies
DrByte
DrByte2y ago
I don't understand your question. Is {brand_name} also '/test'? You can't define panel paths that conflict with your routes files.
nirav77
nirav77OP2y ago
I need to dynamically create panel paths. That's why I've included the {brand_name} prefix in the panel path function. Example URLs for brands: http://localhost/nike/login http://localhost/adidas/login In my frontend, I have a route like http://localhost/blog, it will be considered as part of the brand panel due to the defined prefix. it will give me a 404 Not Found error public function panel(Panel $panel): Panel { return $panel ->id('brand') ->path({brand_name}) ->login() ->registration() ->passwordReset() ->sidebarCollapsibleOnDesktop(); }
DrByte
DrByte2y ago
I think that approach may be the wrong way to go about it in Filament. Since the Panel is a ServiceProvider, it gets registered very early in the bootstrap cycle, and I'm pretty sure at this stage you can't be that dynamic. Maybe the tenancy features are a better fit for your needs? Or maybe you'll need to explore the Panel's HasRoutes trait in Filament\Panel\Concerns\HasRoutes and/or the vendor/filament/filament/routes/web.php code to understand how you could add some dynamic capability into calling the $panel->routes() method.
path() and routes() don't accept closures, so making them dynamic may be challenging. routes() works with arrays though, so maybe you can inject your own? That's one direction you could explore. Check the tenancy-related methods in those same files for additional inspiration/clues for things you could leverage.
Solution
nirav77
nirav772y ago
$this->app->booting(function () { $this->loadRoutesFrom(base_path('./routes/') . "web.php"); }); This code worked for me. In the AppServiceProvider, I needed to load the Laravel route file before the package routes are loaded

Did you find this page helpful?