There is a package that adds relationship events, see this blog post.
https://laravel-news.com/relationship-events
Should work with nova as it's independent to laravel event system but I haven't tried
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Is there a way to listen to when the user attaches/detaches a model in Nova?
There is a package that adds relationship events, see this blog post.
https://laravel-news.com/relationship-events
Should work with nova as it's independent to laravel event system but I haven't tried
Thanks, I hadn't heard of that package. Unfortunately I've tried it and it doesn't work with Nova. I know the package is working by using tinker, but the events aren't triggered by Nova.
@unlikenesses - I dont think this package has anything to do with tinker. It simply adds additional model events for relationships to the core events.
Did this work for you in a non-nova environment?
Say you have a User and Comment with a hasMany relationship (one user has many comments) and belongsTo inverse (A comment belongs to a User) you should be able to add this to your User model
protected static function boot()
{
parent::boot();
static::belongsToAssociated(function ($relation, $related, $parent) {
Log::info("User has been associated with comment {$parent->id}.");
});
}
When you add a new Comment you should see an entry in your logs. If this works without Nova then I would try seeing if when you add a comment in Nova admin panel you see another log message
I meant that I used tinker to check that the events were firing. And they were. So yes it did work for me in a non-nova environment.
I added logging to the listeners, and they are triggered in a non-nova environment (tinker), but they are not triggered in Nova.
@unlikenesses - Im not used to Nova but the doucumentation at https://nova.laravel.com/docs/1.0/resources/#resource-events
Shows you might need to use a Model Observer and register with Nova for this to work. It might work out the box with a model Observer in you model, if you have just used the boot() method above
If not then I'm out of ideas I'm afraid
Thanks for your persistence. You don't need to use Model Observers.
The problem therefore remains. I appreciate your efforts anyway, thanks again @D9705996!
@unlikenesses did you find a solution to this problem?
Please or to participate in this conversation.