Skip to content

Commit

Permalink
dev package
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyentranchung committed May 28, 2024
1 parent 2a7039b commit d6fb13a
Show file tree
Hide file tree
Showing 5 changed files with 1,138 additions and 2 deletions.
75 changes: 75 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

use App\Models\User;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Facades\Auth;

if (! function_exists('formatVND')) {
function formatVND(int $number): string
{
// Format the number with thousands separator and no decimals
$formattedNumber = number_format($number, 0, '', '.');

// Append the Vietnamese currency symbol
return $formattedNumber.'';
}
}

if (! function_exists('authUser')) {
function authUser(): User
{
// @phpstan-ignore-next-line
return Auth::user();
}
}

if (! function_exists('typeString')) {
function typeString(mixed $value, string $fallback = ''): string
{
if (is_string($value)) {
return $value;
}

try {
// @phpstan-ignore-next-line
return strval($value);
} catch (Throwable) {
return $fallback;
}
}
}

if (! function_exists('typeArray')) {
/**
* @param array<mixed> $default
* @return array<mixed>
*
* @throws BindingResolutionException
*/
function typeArray(mixed $value, array $fallback = []): array
{
if (is_array($value)) {
return $value;
}

logger('Expect array -> '.gettype($value));

return $fallback;
}
}

if (! function_exists('typeInteger')) {
function typeInteger(mixed $value, int $fallback = 0): int
{
if (is_int($value)) {
return $value;
}

try {
// @phpstan-ignore-next-line
return intval($value);
} catch (Throwable) {
return $fallback;
}
}
}
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"keywords": [
"laravel",
"framework"
],
"license": "MIT",
"require": {
"php": "^8.2",
"laravel/framework": "^11.0",
"laravel/tinker": "^2.9"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.13",
"barryvdh/laravel-ide-helper": "^3.0",
"fakerphp/faker": "^1.23",
"larastan/larastan": "^2.9",
"laravel/pint": "^1.13",
"laravel/sail": "^1.26",
"mockery/mockery": "^1.6",
Expand Down Expand Up @@ -45,6 +51,10 @@
"@php artisan key:generate --ansi",
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
"@php artisan migrate --graceful --ansi"
],
"ide": [
"php artisan ide-helper:models --write --reset",
"./vendor/bin/pint"
]
},
"extra": {
Expand Down
Loading

0 comments on commit d6fb13a

Please sign in to comment.