- Works with Laravel 10, 11 & 12
- Assigns a unique guest identifier
- Seamlessly migrates guest-owned models to a real user on registration/login
- Simple API, no deep integration needed
composer require MattYeend/guest-to-user-helper
php artisan vendor:publish --tag=config
php artisan vendor:publish --tag=migrationsLaravel 10 and 11
// app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
\MattYeend\GuestToUserHelper\Http\Middleware\AssignGuestIdentifier::class,
],
];Laravel 12
// bootstrap/app.php
use MattYeend\GuestToUserHelper\Http\Middleware\AssignGuestIdentifier;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withMiddleware(function (Middleware $middleware) {
$middleware->group('web', [
AssignGuestIdentifier::class,
]);
})
->create();Add HasGuestOwnership to any model you want to track for guests:
use MattYeend\GuestToUserHelper\Traits\HasGuestOwnership;
class Cart extends Model
{
use HasGuestOwnership;
}Migrate data after login/registration:
app(\MattYeend\GuestToUserHelper\GuestMigrator::class)->migrate(auth()->id());Events available:
GuestMigratingGuestMigrated
Run the included tests:
vendor/bin/phpunitThis package is licensed under the MIT License.
Feel free to fork the repository and submit pull requests for improvements or new features!