File: /mnt/data/ghayatcom/ghayatcom-api/app/Helper/GeneralHelper.php
<?php
namespace App\Helpers;
use App\AdminSettings;
use App\Auditlog;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Auth;
class GeneralHelper
{
public static function setMailConfig() {
//Get the data from settings table
$settings = AdminSettings::firstOrFail();
//Set the data in an array variable from settings table
$mailConfig = [
'transport' => 'smtp',
'host' => $settings->email_host, //smtp.mailgun.org,smtp.googlemail.com
'port' => $settings->email_port, //465,587
'encryption' => 'ssl', //ssl,tls
'username' => $settings->email_username,
'password' => $settings->email_password,
'timeout' => null,
'auth_mode' => null
];
$fromConfig = [
'address' => $settings->email_username,
'name' => env('MAIL_FROM_NAME', 'Ghayatcom')
];
config(['mail.from' => $fromConfig]);
//To set configuration values at runtime, pass an array to the config helper
if($settings->email_driver == 'sendgrid') {
config(['mail.default' => 'sendgrid']);
config(['mail.driver' => 'sendgrid']);
config(['services.sendgrid.api_key' => $settings->sendgrid_api_key]);
} else {
config(['mail.default' => 'smtp']);
config(['mail.mailers.smtp' => $mailConfig]);
}
}
public static function auditLog($message = '', $module = '', $patient = '', $doctor = '')
{
if(!empty($message)) {
$auditlog = new Auditlog();
if(!empty($doctor)) {
$auditlog->doctor_id = $doctor;
}
if(!empty($patient)) {
$auditlog->patient_id = $patient;
}
if(!empty($module)) {
$auditlog->module = $module;
}
$auditlog->description = $message;
if(!empty($patient) && !empty($doctor)) {
$auditlog->created_by = $doctor;
} else if(!empty($patient)) {
$auditlog->created_by = $patient;
} else if(!empty($doctor)) {
$auditlog->created_by = $doctor;
}
$auditlog->save();
}
return true;
}
/**
* Get the authenticated user.
*
* @return \App\User|null
*/
public static function authUser() {
return Auth::user() ?? null;
}
/**
* Get the ID of the authenticated user.
*
* @return int|null
*/
public static function authId() {
return Auth::id() ?? null;
}
public static function authRole() {
return Auth::user()->type ?? null;
}
public static function getCurrentDateTime($format = 'Y-m-d H:i:s') {
return Carbon::now()->format($format);
}
public static function getCurrentDate() {
return self::getCurrentDateTime('Y-m-d');
}
public static function getCurrentTime() {
return self::getCurrentDateTime('H:i:s');
}
public static function userCompliation() {
return [6,7];
}
public static function generateOtpCode() {
return mt_rand(100000,999999);
}
}