F
Filament3mo ago
kaster

Attach Action is not updating the UI

Inside a ViewPage I have a custom Infolist to display data of the model. Also, I created a few custom Actions to create/edit/update data from the record or related records. But, the problem that I'm having is that inside the infolist I have a Tab for products and another for tasks, with a repeater to show the related record. The products is a BelongsToMany relationship and Tasks is a morphMany. Currently I have an action to create a Task and one to attach a Product, but whenever I attach a new products the infolist UI doesnt update (the new attached product is not shown in the repeater), i have to reload the page manually. Can anyone help me solve it, or understand why its happening?
// Create task action

Actions::make([
Action::make('createTask')
->label(trans('Create Task'))
->form([
FormGroup::make()->schema([
TaskCommon::formTitle(),
TaskCommon::formType(),
TaskCommon::formResponsible(),
TaskCommon::formPriority(),
TaskCommon::formStatus(), TaskCommon::formObservation()
->columnSpanFull(),
TaskCommon::formDate(),
])
->columns(),
])
->modalHeading(trans('Create Task'))
->action(function (array $data, Business $record) {
Task::create(array_merge($data, [
'taskable_type' => Business::class,
'taskable_id' => $record->id,
]));
]),

// ->action of the attach

->action(function (array $data, Business $record) {
$product = Product::findOrFail($data['product_id']);
$record->products()->attach($product->id, [
'quantity' => $data['quantity'],
]);
// Create task action

Actions::make([
Action::make('createTask')
->label(trans('Create Task'))
->form([
FormGroup::make()->schema([
TaskCommon::formTitle(),
TaskCommon::formType(),
TaskCommon::formResponsible(),
TaskCommon::formPriority(),
TaskCommon::formStatus(), TaskCommon::formObservation()
->columnSpanFull(),
TaskCommon::formDate(),
])
->columns(),
])
->modalHeading(trans('Create Task'))
->action(function (array $data, Business $record) {
Task::create(array_merge($data, [
'taskable_type' => Business::class,
'taskable_id' => $record->id,
]));
]),

// ->action of the attach

->action(function (array $data, Business $record) {
$product = Product::findOrFail($data['product_id']);
$record->products()->attach($product->id, [
'quantity' => $data['quantity'],
]);
The code is a too extensive, that's why i cant send the full attach action, but it was built as guided by the documentation: https://filamentphp.com/docs/3.x/infolists/actions#adding-anonymous-actions-to-an-infolist-without-attaching-them-to-a-component. I've tried to load the relationship again, but the only thing I found that works is to refresh the page, but its no good to the user.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?