Action to redirect from one panel to another

My Admin Panel lists a User's current nebula_instances. When I click on a specific nebula_instance I want to redirect to the game panel and retain the nebula_instance_id. I've tried many ways (some versions in Pastebin commented out), but can't get it to work. My current error when clicking a nebula_instance is: foreach() argument must be of type array|object, string given Any guidance, direction, an open source project that does this, would be appreciated. I am a coding novice. Thanks. Pastebin for the full files: https://pastebin.com/W5fsJXic#hJGUz6WJ Some select file info that hopefully provides the answer: Standard panels (no dashboard): Admin Game From the NebulaInstanceResource:
->actions([
Action::make('viewGame')
->label('Enter Game')
->icon('heroicon-o-play')
// ->action(function (NebulaInstance $record) {
// session(['nebula_instance_id' => $record->id]);
// return redirect('/game');
// }),

->url('/game')
//->url(fn (NebulaInstance $record) => url('/game?nebula_instance_id=' . $record->id))
->openUrlInNewTab()
])
->actions([
Action::make('viewGame')
->label('Enter Game')
->icon('heroicon-o-play')
// ->action(function (NebulaInstance $record) {
// session(['nebula_instance_id' => $record->id]);
// return redirect('/game');
// }),

->url('/game')
//->url(fn (NebulaInstance $record) => url('/game?nebula_instance_id=' . $record->id))
->openUrlInNewTab()
])
Pastebin
Action to redirect from one panel to another - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
27 Replies
toeknee
toeknee3w ago
Are you sure the games are in different panels? If you want to go to different panels you just do:
ThePanelResource::getUrl('game', 'panel_id', ['record' => $record])
ThePanelResource::getUrl('game', 'panel_id', ['record' => $record])
Randak
RandakOP3w ago
Thanks for the help. I'll test it out ASAP. I tried to chain it in the action but it didn't work.
Action::make('viewGame')
->label('Enter Game')
->icon('heroicon-o-play')
->NebulaInstanceResource::getURL(panel:'game')
Action::make('viewGame')
->label('Enter Game')
->icon('heroicon-o-play')
->NebulaInstanceResource::getURL(panel:'game')
It gives this error: Property 'NebulaInstanceResource' not found in \Filament\Tables\Actions\Action I've tried it a few other ways and places, but same issue. I'm wondering if I broke something fundamental somewhere else.
toeknee
toeknee3w ago
Becauuse it's wrong you should do:
->url(NebulaInstanceResource::getURL('game', 'panel_id', ['record' => $record])
->url(NebulaInstanceResource::getURL('game', 'panel_id', ['record' => $record])
Randak
RandakOP3w ago
Still not working (including variations). I'm more suspicious that I've broken something somewhere or have a fundamental logic and or understanding flaw. I'd be open to a recommendation for reasonably priced paid help.
toeknee
toeknee2w ago
Feel free to DM me so I can understand in more detail what you are tyring to achieve
LeandroFerreira
Could you explain what target you want to redirect to?
Randak
RandakOP2w ago
The User is on their /admin page, which shows the NebulaInstances they are involved in. When they click on a NebulaInstance (action button), it should take them to a new panel (in this context the Game panel). The Game panel will have all the resources for that specific game/instance (key people, ships, etc.). That is why I need to bring over the NebulaInstance reference as well, so they only see the relevant records for that Instance.
LeandroFerreira
->url(\App\Filament\Game\Resources\NebulaInstanceResource::getUrl('index', panel: 'game')) ?
Randak
RandakOP2w ago
\App\Filament\Resources\NebulaIstanceResource
LeandroFerreira
are you sharing this resource to the panels? I didn't understand what/where is the target 🤷‍♂️
Randak
RandakOP2w ago
I'm not sure what that means. I do have the discoverPages and Resources set up. The target is a new page (a new dashboard I believe, even though I'm using the default dashboard). Basically I envision it as a new "admin" panel. The general one for the user. Then another panel with all the information for a specific instance for the game. Sorry if my knowledge level makes this more difficult--Filament is wonderful but I'm still learning to code and use it.
LeandroFerreira
I do have the discoverPages and Resources set up same path to both panels?
Randak
RandakOP2w ago
Yes. Do I need to set up separate directories?
LeandroFerreira
I think this was supposed to work
Tables\Actions\Action::make('viewGame')
->url(\App\Filament\Resources\NebulaIstanceResource::getUrl('index', panel: 'game'))
Tables\Actions\Action::make('viewGame')
->url(\App\Filament\Resources\NebulaIstanceResource::getUrl('index', panel: 'game'))
what is the url for accessing this action?
Randak
RandakOP2w ago
/admin/nebula-instances
LeandroFerreira
Is it redirecting to the game panel? hum, weird
Randak
RandakOP2w ago
I may have messed up a fundamental some where. That is where it may be beneficial to have someone look at my code. I've tried so many ways who knows what damage I've done! 🙂
LeandroFerreira
are you able to create a minimal project on github, with panels and one resource, to reproduce this issue? I can take a look
Randak
RandakOP2w ago
I have it pushed to gitub, including seeders.
Randak
RandakOP2w ago
Just set public, here is the link: https://github.com/House-Chaos-Games/ChaosEmpire
GitHub
GitHub - House-Chaos-Games/ChaosEmpire
Contribute to House-Chaos-Games/ChaosEmpire development by creating an account on GitHub.
LeandroFerreira
->actions([
Action::make('viewGame')
->label('Enter Game')
->icon('heroicon-o-play')
->url(fn (NebulaInstance $record) => NebulaInstanceResource::getUrl('index', panel: 'game'))
->tooltip(fn (NebulaInstance $record) => NebulaInstanceResource::getUrl('index', panel: 'game'))
->openUrlInNewTab()
])
->actions([
Action::make('viewGame')
->label('Enter Game')
->icon('heroicon-o-play')
->url(fn (NebulaInstance $record) => NebulaInstanceResource::getUrl('index', panel: 'game'))
->tooltip(fn (NebulaInstance $record) => NebulaInstanceResource::getUrl('index', panel: 'game'))
->openUrlInNewTab()
])
No description
Randak
RandakOP2w ago
This error (which I've gotten frequently during this process): foreach() argument must be of type array|object, string given GET localhost PHP 8.3.9 — Laravel 11.16.0 Expand vendor frames 24 vendor frames collapsed storage/framework/views/4943bc92ebba41e8b0e508149542e0ad.blade.php :16 require 62 vendor frames collapsed public/index.php :17 require_once 1 vendor frame collapsed storage/framework/views/4943bc92ebba41e8b0e508149542e0ad.blade.php :16 $env->slot($name, attributes: $slot->attributes->getAttributes()); echo $slot->toHtml(); $env->endSlot(); } ?> @endcomponent
LeandroFerreira
this is not related to the issue I think
Randak
RandakOP2w ago
It happens when I click on the button. Maybe I messed something up earlier in the process. I wonder if that view is delectable (without breaking something else)?
LeandroFerreira
probably you need to inspect your code this isn't related to the main issue
Randak
RandakOP2w ago
So many hours.... hahahaha I really appreciate your help. I've done business coaching and consulting for 40 years so if you need any business help I'm at your service! (this applies to you as well @toeknee )
LeandroFerreira
thanks ✌️

Did you find this page helpful?