77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Helper
|
|
{
|
|
public static function formatCurrency(float $amount, string $currency = 'IDR'): string
|
|
{
|
|
if ($currency === 'IDR') {
|
|
return 'Rp '.number_format($amount, 0, ',', '.');
|
|
}
|
|
|
|
return $currency.' '.number_format($amount, 2, '.', ',');
|
|
}
|
|
|
|
public static function maskPhone(string $phone): string
|
|
{
|
|
$phone = preg_replace('/\D/', '', $phone);
|
|
|
|
if (strlen($phone) < 10) {
|
|
return $phone;
|
|
}
|
|
|
|
$maskedLength = strlen($phone) - 4;
|
|
$masked = substr($phone, 0, 3).str_repeat('*', $maskedLength).substr($phone, -4);
|
|
|
|
return $masked;
|
|
}
|
|
|
|
public static function generateSubdomain(string $name): string
|
|
{
|
|
$slug = Str::slug($name, '-');
|
|
$slug = preg_replace('/[^a-z0-9-]/', '', $slug);
|
|
$slug = preg_replace('/-+/', '-', $slug);
|
|
$slug = trim($slug, '-');
|
|
|
|
return $slug;
|
|
}
|
|
|
|
public static function getTenantDatabaseName(string $subdomain): string
|
|
{
|
|
return 'profitra_'.str_replace('-', '_', strtolower($subdomain));
|
|
}
|
|
|
|
public static function sanitizeInput(string $input): string
|
|
{
|
|
$input = trim($input);
|
|
$input = stripslashes($input);
|
|
$input = htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
|
|
|
|
return $input;
|
|
}
|
|
|
|
public static function isEmail(string $value): bool
|
|
{
|
|
return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
|
|
}
|
|
|
|
public static function isUrl(string $value): bool
|
|
{
|
|
return filter_var($value, FILTER_VALIDATE_URL) !== false;
|
|
}
|
|
|
|
public static function getCurrentUrl(): string
|
|
{
|
|
return URL::current();
|
|
}
|
|
|
|
public static function getBaseUrl(): string
|
|
{
|
|
return url('/');
|
|
}
|
|
}
|