File: D:/HostingSpaces/debout/debout.nl/app/Facades/Format.php
<?php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Format extends Facade
{
protected static function getFacadeAccessor()
{
return 'format';
}
/**
* Format input as price
*
* @param $input
* @param array $options
* @return string
*/
static public function asPrice($input, $options = ['currency' => ''])
{
$decimals = false;
$output = '';
if( ! empty($options['currency'])) $output .= '<span class="currency">' . htmlentities($options['currency']) . '</span>';
$input = (string) $input / 100;
//Only show two decimals
$input = number_format($input,2);
$parts = explode('.',$input);
// Check units
$units = $parts[0];
// Check decimals
if( isset($parts[1]) )
{
$decimals = $parts[1];
$decimals = str_pad($decimals, 2, '0', STR_PAD_RIGHT);
}
else
{
$decimals = '00';
}
// Loop through units
foreach(str_split($units) as $char)
{
$output .= '<span class="unit">' . $char . '</span>';
}
$output .= '<span class="point">,</span>';
// Loop through decimals
foreach(str_split($decimals) as $char)
{
$output .= '<span class="decimal">' . $char . '</span>';
}
return $output;
}
static public function asFlatPrice($input, $options = ['currency' => ''])
{
if(! is_numeric($input)) return $input;
$output = number_format($input / 100, 2, ',', '');
if($options['currency']) $output = $options['currency'] . ' ' . $output;
return $output;
}
static public function asPercentage($input)
{
if(! is_numeric($input)) return $input;
return round($input * 100) / 100;
}
}