<?php
namespace App\Helpers;

use App\Models\ErrorLog;
use Illuminate\Support\Facades\Auth;

class LogHandler
{
    public static function logError(\Throwable $th)
    {
        $user_info = "Utilisateur non connecté";
        $user_array="";
        $serveur="";
        if(Auth::check()){
            $user_array = Auth::user();
            $user_info = "";
            $serveur="";
        }

        ErrorLog::create([
            'error_message' => $th->getMessage(),
            'file' => $th->getFile(),
            'line' => $th->getLine(),
            'stack_trace' => $th->getTraceAsString(),
            'user_array' => $user_array ?? "",
            'user_info' => $user_info ?? "",
            'serveur' => $serveur ?? "",
        ]);
    }
}
