Created
March 21, 2024 14:08
-
-
Save DesolatorMagno/53d06bc35c0576e5ca6785401c86b9dc to your computer and use it in GitHub Desktop.
Helper functions (Laravel)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Helpers; | |
use DateTime; | |
use Illuminate\Database\Eloquent\Collection; | |
use Illuminate\Support\Facades\Crypt; | |
class General | |
{ | |
static function generateUniqueId(string $prefix = '', bool $moreEntropy = true): string | |
{ | |
return uniqid($prefix, $moreEntropy); | |
} | |
public static function validateDate(string $date, string $format = 'Y-m-d'): bool | |
{ | |
$d = DateTime::createFromFormat($format, $date); | |
return $d && $d->format($format) == $date; | |
} | |
public static function decrypt(?string $field): ?string | |
{ | |
if ($field && strlen($field) > 35) { | |
return Crypt::decryptString($field); | |
} | |
return $field; | |
} | |
public static function encrypt(?string $field): ?string | |
{ | |
if ($field) { | |
return Crypt::encryptString($field); | |
} | |
return $field; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment