mattyeend/guest-to-user-helper

Guest-to-user migration helper for Laravel.

v1.1.4 2025-08-21 20:02 UTC

This package is auto-updated.

Last update: 2025-08-21 20:03:27 UTC


README

Features

  • 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

Install

composer require MattYeend/guest-to-user-helper
php artisan vendor:publish --tag=config
php artisan vendor:publish --tag=migrations

Middleware Registration

Laravel 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();

Usage

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:

  • GuestMigrating
  • GuestMigrated

Testing

Run the included tests:

vendor/bin/phpunit

License

This package is licensed under the MIT License.

Contributing

Feel free to fork the repository and submit pull requests for improvements or new features!