First off, I'm defining an "anonymous user" as the user who signs in via a "guest login". A one-tap way to create a new guest account and get in-game to try things out without pledging your email or committing a new password to memory.
So let's walk through how I designed the anonymous user functionality for Trounced (new kingdom-builder browser game) in Laravel.
I have opted to put this as an attribute on the User model to easily tell if a user is a guest: // User Model public function isGuest(): Attribute { return new Attribute( get: fn ($v, $attr) => $attr['email'] === null, ); }
We add the Prunable trait to the User model and then define a new prunable method to define the appropriate criteria.