Redirect after custom action

Hi, I have a PostResource with a table, where users can top their posts, which creates a payment. I would like to redirect the user to the PaymentResource with a specific ID of Payment in infolist, which I want to show in modal. How can I do it, please? So far I have this code: PostResource in table:
Action::make('top')
->form([
Forms\Components\Select::make('type')
->label('Top')
->options([
'small' => getPostDetail('small')->price . '€' . ' ' . getPostDetail('small')->name . ' (' . getPostDetail('small')->duration . ' days)',
'topped' => getPostDetail('topped')->price . '€' . ' ' . getPostDetail('topped')->name . ' (' . getPostDetail('topped')->duration . ' days)',
'popup' => getPostDetail('popup')->price . '€' . ' ' . getPostDetail('popup')->name . ' (' . getPostDetail('popup')->duration . ' days)'
])
->required()
])
->action(function (array $data, Post $post) {
$payment = new Payment();

$payment->post()->associate($post);
$payment->user()->associate(auth()->user());
$payment->type = $data['type'];
$payment->price = getPostDetail($data['type'])->price;

$payment->save();

$payment->user->notify(new PaymentCreated($payment));

Notification::make()
->title('You have created a new payment.')
->icon('heroicon-o-check-circle')
->iconColor('success')
->send();

// Redirect here and open infolist?
}),)
Action::make('top')
->form([
Forms\Components\Select::make('type')
->label('Top')
->options([
'small' => getPostDetail('small')->price . '€' . ' ' . getPostDetail('small')->name . ' (' . getPostDetail('small')->duration . ' days)',
'topped' => getPostDetail('topped')->price . '€' . ' ' . getPostDetail('topped')->name . ' (' . getPostDetail('topped')->duration . ' days)',
'popup' => getPostDetail('popup')->price . '€' . ' ' . getPostDetail('popup')->name . ' (' . getPostDetail('popup')->duration . ' days)'
])
->required()
])
->action(function (array $data, Post $post) {
$payment = new Payment();

$payment->post()->associate($post);
$payment->user()->associate(auth()->user());
$payment->type = $data['type'];
$payment->price = getPostDetail($data['type'])->price;

$payment->save();

$payment->user->notify(new PaymentCreated($payment));

Notification::make()
->title('You have created a new payment.')
->icon('heroicon-o-check-circle')
->iconColor('success')
->send();

// Redirect here and open infolist?
}),)
Thank you for help.
11 Replies
DZUSILL
DZUSILLOP5mo ago
Anyone, please? 😔
awcodes
awcodes5mo ago
Maybe inject $livewire into the action() callback and $livewire->redirect()
DZUSILL
DZUSILLOP5mo ago
I made so far in the action function:
$livewire->redirect(route('filament.admin.resources.payments.view', ['record' => $payment->id]));
$livewire->redirect(route('filament.admin.resources.payments.view', ['record' => $payment->id]));
made custom page with view record parameter and view-payment.blade file:
<x-filament::page>
<x-filament::infolist :record="$payment" />
</x-filament::page>
<x-filament::page>
<x-filament::infolist :record="$payment" />
</x-filament::page>
but this opens a whole new page, not the modal as I want to
awcodes
awcodes5mo ago
Maybe I’m just not understanding. A redirect will always open another page. That’s what a redirect does. Are you trying to swap the modal.?
DZUSILL
DZUSILLOP5mo ago
I have a PostResource, where there is an action to top the post. After clicking the custom action "top", it creates a Payment with the current post_id what user wants to top. After the Payment is created, I have a PaymentResource, where I want the user to be redirect, or just simply show him $infolist in the PaymentResource, where are all details to pay for topping the post. The custom action in PostResource:
return $table
->actions([
Action::make('top')
->action(function (array $data, Post $post, $livewire) {
$payment = new Payment();

$payment->post()->associate($post);
$payment->user()->associate(auth()->user());
$payment->type = $data['type'];
$payment->price = getPostDetail($data['type'])->price;

$payment->save();
$payment->user->notify(new PaymentCreated($payment));

Notification::make()
->title('You have created a new payment.')
->icon('heroicon-o-check-circle')
->iconColor('success')
->send();

$livewire->redirect(route('filament.admin.resources.payments.view', ['record' => $payment->id]));
}),
]),
]);
return $table
->actions([
Action::make('top')
->action(function (array $data, Post $post, $livewire) {
$payment = new Payment();

$payment->post()->associate($post);
$payment->user()->associate(auth()->user());
$payment->type = $data['type'];
$payment->price = getPostDetail($data['type'])->price;

$payment->save();
$payment->user->notify(new PaymentCreated($payment));

Notification::make()
->title('You have created a new payment.')
->icon('heroicon-o-check-circle')
->iconColor('success')
->send();

$livewire->redirect(route('filament.admin.resources.payments.view', ['record' => $payment->id]));
}),
]),
]);
The infolist (I want to show after redirect in modal) in the PaymentResource:
return $infolist
->schema([
Section::make('Bank details')
->description('Send here:')
->icon('heroicon-m-building-library')
->columns([
'sm' => 1,
'xl' => 2,
])
->schema([
TextEntry::make('post')
->prefix('#')
->state(fn($record) => $record->post_id ?? $record->banner_id),
TextEntry::make('payment_type'),
TextEntry::make('bank_account'),
TextEntry::make('variable_symbol')
->state(fn($record) => $record->id),
]),
]);
return $infolist
->schema([
Section::make('Bank details')
->description('Send here:')
->icon('heroicon-m-building-library')
->columns([
'sm' => 1,
'xl' => 2,
])
->schema([
TextEntry::make('post')
->prefix('#')
->state(fn($record) => $record->post_id ?? $record->banner_id),
TextEntry::make('payment_type'),
TextEntry::make('bank_account'),
TextEntry::make('variable_symbol')
->state(fn($record) => $record->id),
]),
]);
lazydog
lazydog5mo ago
Try something like this
$livewire->redirect(PaymentResouce::getUrl('view', ['record' => $recordRelatedForPayment]))
$livewire->redirect(PaymentResouce::getUrl('view', ['record' => $recordRelatedForPayment]))
DZUSILL
DZUSILLOP5mo ago
Hi, that doesn't, it opens the page, not the modal after the redirect 😕
awcodes
awcodes5mo ago
Redirects aren’t going to open a modal. You need an action to do that.
DZUSILL
DZUSILLOP5mo ago
How could I do that, please? Sorry, I'm new in the Filament
DZUSILL
DZUSILLOP5mo ago
Thanks.
Want results from more Discord servers?
Add your server