Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

see_kay's avatar

Fetching activitylog for a specific model instance (using spatie/laravel-activitylog)

I'm new to Laravel so a little confused by this...

I'm using the https://github.com/spatie/laravel-activitylog package to log model events to the database and that's working fine. So if I create a task and then add comments to it, and the activitylog for both is saved correctly to the database. (Here a 'Comment' has a polymorphic relationship with a 'Task'.)

However, I'd now like to retrieve all recent activity for a task and its comments - the example in the documentation is useful but pretty basic in that it shows a store and immediate retrieval of the very last entry. How do I get recent activity for a specific task i.e. $task->activity and $task->comments->activity ?

0 likes
2 replies
see_kay's avatar

Never mind, $task->activity works out of the box (doh!) and $task->comments->activity can't work since its activity for multiple comments... I'd have to fetch a collection myself, but the more I think about it, it wouldn't make sense to try and show activity fo all comments under a specific task...

FallenKnight85's avatar

Does this still work? I'm trying to get activity on my model buy using $model->activity as commented but none is returned. There is data in the activity_log table though.

Please or to participate in this conversation.