Viewing File: /home/ubuntu/voice-assistant-backend/app/Helpers/viewHelper.php
<?php
use Carbon\Carbon;
/**
* To get & format the translation messages.
*
* @created Karthick
*
* @param string
* @param array
*
* @return string
*/
function tr($message, $placeholders = [])
{
return __("messages.$message", $placeholders);
}
/**
* To get & format the translation api success messages.
*
* @created Karthick
*
* @param int
* @param array
*
* @return string
*/
function api_success($code , $placeholders = [])
{
return __("api-success.$code", $placeholders);
}
/**
* To get & format the translation api error messages.
*
* @created Karthick
*
* @param int
* @param array
*
* @return string
*/
function api_error($code , $placeholders = [])
{
return __("api-error.$code", $placeholders);
}
/**
* To create an empty object.
*
* @return object
*/
function emptyObject()
{
return (Object)[];
}
/**
* To check the aws configuration.
*
* @created Karthick
*
* @return bool
*/
function check_aws_configuration(): bool
{
return config('app.aws.key_id') && config('app.aws.secret_key') && config('app.aws.region') && config('app.aws.bucket');
}
/**
* To convert the timestamp from app timezone to specified timezone.
*
* @created Karthick
*
* @return string
*/
function timezone_conversion($timestamp, $timezone, $format = 'd M Y h:i A'): string
{
return Carbon::createFromTimeString($timestamp, config('app.timezone'))->setTimezone($timezone)->format($format);
}
/**
* To format 2FA formatted text.
*
* @created Karthick
*
* @param int
* @return string
*/
function tfa_status_formatted($status): string
{
return $status ? tr('basic.enabled') : tr('basic.disabled');
}
/**
* To format email status formatted text.
*
* @created Karthick
*
* @param int
* @return string
*/
function email_status_formatted($status): string
{
return $status ? tr('basic.verified') : tr('basic.pending');
}
/**
* To format status formatted text.
*
* @created Karthick
*
* @param int
* @return string
*/
function status_formatted($status): string
{
return $status ? tr('basic.approved') : tr('basic.declined');
}
/**
* To remove special characters from a string.
*
* @created Karthick
*
* @param string
* @return string
*/
function clean($string) {
$string = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $string));
$search = [' ', '&', '%', "?",'=','{','}','$'];
$replace = ['-', '-', '-' , '-', '-', '-' , '-','-'];
$string = preg_replace('/-+/', '-', str_replace($search, $replace, $string));
return $string;
}
Back to Directory
File Manager