F
Filament13mo ago
Askancy

Function in aftersave() is not executed

I have this custom function:
CreateTopic('3', $record->titolo, $record->testo, '56')
CreateTopic('3', $record->titolo, $record->testo, '56')
When I use it as Action it works correctly:
Action::make('Generate Topic')
->label('')
->icon('far-comments')
->action(function (Articoli $record): void {
$cTopic = CreateTopic('3', $record->titolo, $record->testo, '56');
$id_topic = json_decode($cTopic->getBody());
},
Action::make('Generate Topic')
->label('')
->icon('far-comments')
->action(function (Articoli $record): void {
$cTopic = CreateTopic('3', $record->titolo, $record->testo, '56');
$id_topic = json_decode($cTopic->getBody());
},
For when I use it in CreateArticle.php as afterSave(), it doesn't execute--how come?
protected function afterSave(): void
{
if ($this->record->is_published === 'Published') {
$cTopic = CreateTopic('3', $this->record->titolo, $this->record->testo, '56');
$id_topic = json_decode($cTopic->getBody());
}
}
protected function afterSave(): void
{
if ($this->record->is_published === 'Published') {
$cTopic = CreateTopic('3', $this->record->titolo, $this->record->testo, '56');
$id_topic = json_decode($cTopic->getBody());
}
}
5 Replies
awcodes
awcodes13mo ago
You might need to tap the record so you have a fresh instance of it. My guess is the record’s published status might not be what you’re expecting it to be.
Askancy
AskancyOP13mo ago
Sorry, I guess I don't understand what you mean by " tap the record to get a new instance."
awcodes
awcodes13mo ago
Try $record = $this->record->fresh() and change the references of $this->record to just $record. I say tap because there’s a laravel function tap() that essentially does the same thing. What I’m getting at is that you need to make sure the is_published it correct or your logic won’t run.
Askancy
AskancyOP13mo ago
It kept not going and I realized the error.... a very stupid mistake that we didn't think....😂😂 afterSave is for EditArticle, for CreateArticle is afterCreate
awcodes
awcodes13mo ago
There’s that too. Glad you figured it out.
Want results from more Discord servers?
Add your server