<?php

namespace App\Helpers;

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

class AuditTrailHelper
{
	public static function AddAuditTrail($action, $activity)
	{
		$audit = new AuditTrail();
		$audit->user_id = Auth::user()->id;
		$audit->ip_address = request()->ip();
		$audit->activity = $activity;
		$audit->action = $action;
		$audit->user_agent = request()->userAgent();
		$audit->browser = substr($audit->user_agent, 0, strpos($audit->user_agent, '/'));
		$audit->save();
	}

	public static function AuthAttempt($action, $activity)
	{
		$audit = new AuditTrail();
		$audit->ip_address = request()->ip();
		$audit->activity = $activity;
		$audit->action = $action;
		$audit->user_agent = request()->userAgent();
		$audit->browser = substr($audit->user_agent, 0, strpos($audit->user_agent, '/'));
		$audit->save();
	}
}