seems that the problem is here...but why?
class AddStoryAttributes
{
public function __invoke(UserSerializer $serializer, User $user, array $attributes): array
{
$actor = $serializer->getActor();
$attributes['canCreateStory'] = $actor->can('createStory', $user);
$attributes['storyCount'] = $actor->stories()->count();
$attributes['canViewGlobalStories'] = $actor->can('viewStory', $user);
$attributes['canDeleteStory'] = $actor->can('deleteStory', $user);
$attributes['canEditStory'] = $actor->can('editStory', $user);
return $attributes;
}
}
EDIT: i've found a solutions with a condition
if ($actor->isGuest()) {
$attributes['storyCount'] = 0;
} else {
$attributes['storyCount'] = $actor->stories()->count();
}