Create table header action question...

I'm using just the table builder package and have a quick question: - When I implement a create record table header action, how do I get the action to return to the list page when done? I have tried using successRedirectUrl()...but no redirect occurs. The record is created, but that's it.
17 Replies
Dan Harrin
Dan Harrin2y ago
you can route()->redirect() inside the action()
Travis
TravisOP2y ago
I don't have and don't need, apparently, any action() call. Here's what I have in my table component:
protected function getTableHeaderActions(): array
{
return [
Tables\Actions\CreateAction::make('create')
->url(route('posts.create'))
->icon('heroicon-o-plus')
->button(),
];
}
protected function getTableHeaderActions(): array
{
return [
Tables\Actions\CreateAction::make('create')
->url(route('posts.create'))
->icon('heroicon-o-plus')
->button(),
];
}
The 'posts.create' route shows a filament form that, when submitted, creates the new resource, but nothing else...no redirect/return. I feel like I'm missing something again....
Dan Harrin
Dan Harrin2y ago
have you told it to redirect when the form is submitted?
Travis
TravisOP2y ago
As noted, I tried to do so via the successRedirectUrl()...but it doesn't appear to work, so I'm either using it incorrectly or there's some other way...? 🤔 I was also just told elsewhere to try to use redirectRoute(), which my IDE doesn't hint/suggest, so I didn't know it was a possibility....and didn't see it when looking through the filament code. So...I'll try that shortly....
Dan Harrin
Dan Harrin2y ago
show me where you are submitting the form it sounds like its not anything related to filament
Travis
TravisOP2y ago
It may not have anything to do with filament.... Anyway, here's the create() method for my CreatePost form:
public function create(): void
{
$data = $this->form->getState();

$record = Post::create($data);

$this->form->model($record)->saveRelationships();
}
public function create(): void
{
$data = $this->form->getState();

$record = Post::create($data);

$this->form->model($record)->saveRelationships();
}
Dan Harrin
Dan Harrin2y ago
so where are you redirecting then?
Travis
TravisOP2y ago
I tried to redirect from the table component's getTableHeaderActions() method by calling successRedirectUrl() on the action, passing the route that displays the table component.
Dan Harrin
Dan Harrin2y ago
the action is just a button it is just an <a> it sends the user to the create page the create page is responsible for redirecting the user back
Travis
TravisOP2y ago
OK. I guess that makes sense...and seems like it should have been obvious. Sorry....
Dan Harrin
Dan Harrin2y ago
the only time an action will redirect is if it isnt a url() when it opens a modal or something
Travis
TravisOP2y ago
Is this the way that you anticipate users of the table-builder to work, then...? To have the create/edit forms responsible for redirecting to where they need to go...? With admin panel, it seems like there's the "layer" that ties all these things together nicely, but when using just the table-builder package, then it's on me to know that when I'm done creating, I want to go back to the list...and when I'm done editing, I want to go back to viewing the individual resource, or, perhaps, returning to the list....?
Dan Harrin
Dan Harrin2y ago
yes thats the whole point
Travis
TravisOP2y ago
It's 100% up to me to implement that wiring from the create/edit forms....
Dan Harrin
Dan Harrin2y ago
in the admin panel this is done for you outside, its a normal laravel app
Travis
TravisOP2y ago
Alright...so the redirectXyz() methods on the actions....what are they for...? Is that for when a modal form is used...? Referring to Filament\Support\Actions\Concerns\CanRedirect
Dan Harrin
Dan Harrin2y ago
those are for our built-in actions like CreateAction, EditAction. which open modals.
Want results from more Discord servers?
Add your server