File: D:/HostingSpaces/SBogers10/zipwire.komma.pro/app/KommaApp/Kms/ActionLog/ActionLogger.php
<?php
namespace App\KommaApp\Kms\ActionLog;
use App\KommaApp\Users\Models\User;
class ActionLogger
{
/**
* Log an action to the database
*
*
* @param string $actionText
* @param null $payLoad Example: "['route' => '/login']". Don't make it to big!
* @param User|null $user The user or null for the authenticated user / anonymous
* @return ActionLog
*/
public static function Log(string $actionText, $payLoad = null, User $user = null):ActionLog
{
if(!$user) if(\Auth::user()) $user = \Auth::user();
$action = new ActionLog();
$action->User()->associate($user);
$action->action = $actionText;
if($payLoad) $action->payload = $payLoad;
$action->save();
return $action;
}
}