使用令牌 (jrean/laravel-user-verification) 单击 link 后自动登录

Automatic login after clicking on the link with the token (jrean/laravel-user-verification)

我使用 "jrean/laravel-user-verification" 包。当我单击带有令牌的 link 时,我想在我的主页中重定向并已登录。我该如何实施?谢谢)

Laravel: 5.4 软件包版本:4.1

解决这个问题。添加到我的 register 函数 (RegisterController) event:

public function register(VerificationRequest $request)
 {
       ...
       event(new Registered($user));
       ...
 }

С创建 监听器:

<?php

namespace App\Listeners;

use Illuminate\Auth\AuthManager;
use Jrean\UserVerification\Events\UserVerified;

/**
 * Class UserVerifiedListener
 * @package App\Listeners
 */
class UserVerifiedListener
{
    /**
     * @var AuthManager
     */
    private $auth;

    /**
     * Create the event listener.
     *
     * @param AuthManager $auth
     */
    public function __construct(AuthManager $auth)
    {
        $this->auth = $auth;
    }

    /**
     * Handle the event.
     *
     * @param  UserVerified  $event
     * @return void
     */
    public function handle(UserVerified $event)
    {
        $this->auth->guard()->login($event->user);
    }
}

并在 :

中注册
app/Providers/EventServiceProvider.php
<?php

namespace App\Providers;

use App\Listeners\UserVerifiedListener;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Jrean\UserVerification\Events\UserVerified;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        UserVerified::class => [
            UserVerifiedListener::class
        ],
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        //
    }

    public function register()
    {
        $this->app->bind(UserVerifiedListener::class, function () {
            return new UserVerifiedListener(
                $this->app->make('auth')
            );
        });
    }
}