spatie / laravel-activitylog

Log activity inside your Laravel app
https://docs.spatie.be/laravel-activitylog
MIT License
5.3k stars 712 forks source link

Allow for safer fallback of causer resolver #1229

Closed grantholle closed 10 months ago

grantholle commented 11 months ago

Right now when using non-Eloquent auth provider drivers, things can sometimes break when logging model events. For example, using a simple token guard driver and database provider driver, the logged in user is an instance of Illuminate\Auth\GenericUser. When model events get fired, the user is not an instance of Model and is also not null, so a TypeError gets thrown.

This change will make the default resolver more forgiving and will prevent a TypeError when the current user is not an instance of Model, while still maintaining the ability to override the causer using the normal means. Since Auth::user() (which is the the current logic of the default causer resolver) is meant to return an instance of Illuminate\Contracts\Auth\Authenticatable rather than Model, I think this is a reasonable fallback.