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.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners