The CauserResolver class handles resolving who caused an activity. It is registered as a scoped binding (per request) in the container.
For most use cases, you should use the Activity facade instead of interacting with CauserResolver directly:
use Spatie\Activitylog\Facades\Activity;
Activity::defaultCauser($admin, function () {
});
Activity::defaultCauser($admin);
##Advanced usage
If you need lower-level control, resolve the CauserResolver from the container:
use Spatie\Activitylog\Support\CauserResolver;
app(CauserResolver::class)->resolveUsing(function ($subject) {
return User::find(1);
});
Note: setCauser() takes priority over resolveUsing().
##Methods
##resolve
public function resolve(Model | int | string | null $subject = null): ?Model;
##resolveUsing
public function resolveUsing(Closure $callback): static;
##setCauser
public function setCauser(?Model $causer): static;
##withCauser
public function withCauser(?Model $causer, Closure $callback): mixed;