Function in aftersave() is not executed
I have this custom function:
When I use it as Action it works correctly:
For when I use it in CreateArticle.php as afterSave(), it doesn't execute--how come?
5 Replies
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.
Sorry, I guess I don't understand what you mean by " tap the record to get a new instance."
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.
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
There’s that too. Glad you figured it out.