<?php

namespace App\Listeners;

use Illuminate\Auth\Events\Login;
use App\Models\Audit;

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

    /**
     * Handle the event.
     *
     * @param  Login  $event
     * @return void
     */
    public function handle(Login $event)
    {
        Audit::create([
            'user_id' => $event->user->id,
            'model' => 'App\Models\User',
            'model_id' => $event->user->id,
            'action' => 'login',
            'url' => request()->fullUrl(),
            'method' => request()->method(),
            'ip' => request()->ip(),
            'user_agent' => request()->userAgent()
        ]);
    }
} 