feat: custom helper

This commit is contained in:
Yoga Pangestu 2024-11-23 10:34:20 +07:00
parent 56edf0c680
commit 4880d88ffb
4 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,12 @@
<?php
use Carbon\Carbon;
if (! function_exists('formatDateIndo')) {
function formatDateIndo($date, $format = 'l, d F Y', $locale = 'id')
{
Carbon::setLocale('id');
return Carbon::parse($date)->translatedFormat('D, d M Y');
}
}

View File

@ -0,0 +1,21 @@
<?php
use Hashids\Hashids;
if (! function_exists('encryptId')) {
function encryptId($id)
{
$hashids = new Hashids('PiscokGodog');
return $hashids->encode([$id, 54715]);
}
}
if (! function_exists('decryptId')) {
function decryptId($hashId)
{
$hashids = new Hashids('PiscokGodog');
return $hashids->decode($hashId)[0];
}
}

View File

View File

@ -0,0 +1,21 @@
<?php
if (! function_exists('removeRupiahFormatting')) {
function removeRupiahFormatting($value)
{
$convertedValue = str_replace(['Rp', '.', ' '], '', $value);
$convertedValue = str_replace(',', '.', $convertedValue);
return $convertedValue;
}
}
if (! function_exists('formatToRupiah')) {
function formatToRupiah($value)
{
$valueFormatted = 'Rp'.number_format($value, 2, ',', '.');
return $valueFormatted;
}
}