<?php

namespace App\Listeners;

use App\Events\UserLogEvent;
use App\Models\Logs;
use Carbon\Carbon;

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

    /**
     * Handle the event.
     *
     * @param UserLogEvent $event
     * @return void
     */
    public function handle(UserLogEvent $event)
    {
        if (auth()->check()) {
            $ul = new Logs();
            $ul->added_by = auth()->id();
            $ul->model_id = $event->model_id ?? null;
            $ul->model_name = $event->model_name;
            $ul->message = $event->message;
            $ul->save();
        }
    }
}
