1

ユーザーが詳細を入力するために初めてユーザーログインを作成したいのですが、ユーザーが2回目にログインして詳細を入力した後、詳細の入力ページに戻りません。

そこで、Last_Login_at の値を Null に更新して 1 にするイベントを作成し、ユーザーがこの部分をエスケープできるようにします。

私はここで何か間違っていますか?

イベント

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class UserHaveStoreTheFormEvent
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $user;

    /**
     * Create a new event instance.
     *
     * @param $user
     */
    public function __construct($user)
    {
        $this->user = $user;
    }

}

リスナー

<?php

namespace App\Listeners;
use App\Events\UserHaveStoreTheFormEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class WelcomeNewUser
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        $user = auth()->user();
        $user->last_login_at = 1;
        $user->save();
    }
}

イベントサービス

<?php

namespace App\Providers;

use App\Events\UserHaveStoreTheFormEvent;
use App\Listeners\WelcomeNewUser;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        [
            UserHaveStoreTheFormEvent::class =>[
                WelcomeNewUser::class,
            ],
        ],
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],

    ];

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

        //
    }
}

コントローラ

  public function store(StoreCustomerRequest $request)
    {
        $user = Customer::create($request->all());

        event(new UserHaveStoreTheFormEvent($user));

        return redirect()->route('admin.customers.index');
    }
4

1 に答える 1