<?php

namespace App\Listeners;

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

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

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