A set of helper utilities and traits to common functions we use everyday and across all our systems.
PHP 8.1+
Laravel 9+
You can install the package via composer:
composer require propaysystems/utilities
You can publish the config file with:
php artisan vendor:publish --tag="utilities-config"
Clears all data and reset auto increment on given table.
DatabaseHelper::resetTable($table);
This will get the month name of the month number you pass in. Abbreviation will return the short name of the month.
DateHelper::getMonthName($number, $abbreviation = false);
Get current financial year of South Africa
DateHelper::getFiscalYear();
Get time
DateHelper::getTime($string);
This will get the human-readable format of the bytes you pass in
FileHelper::formatBytes($bytes, $precision = 2);
Get the currently assigned public ip address of the request
HttpHelper::getIp();
Get the currently useragent of the request
HttpHelper::getUserAgent();
Get the hostname/domain name of the system. You can specify full to return http::// parts aswell
HttpHelper::hostname($full = false);
Get the subdomain of the current system
HttpHelper::subdomain();
Generate a fake id number for testing from the date of birth
IdNumberHelper::generateIdNumber($dateOfBirt, int $male = 1);
Generate a complete fake id number for testing
IdNumberHelper::generateFakeNumber($dateOfBirt, int $male = 1);
Get gender from the id number
IdNumberHelper::getGenderCode($idNumber);
Get the date of birth from the id number
IdNumberHelper::getBirthDate($idNumber);
Get age from the id number
IdNumberHelper::getAgeFromIdNumber($idNumber);
Validate the id number
IdNumberHelper::getAgeFromIdNumber($attribute, $value, $parameters);
Will generate a random integer between 1 and 100 000
NumberHelper::randomInt();
Will get the % difference between 2 number
NumberHelper::getPercentageDifference(int $last, int $current);
This will format the number accordingly 100000 will become 100.00k
NumberHelper::numberFormat(int $number);
This will combine a country prefix ex: 27 with the cell number ex: 0821231234 and return 27821231234
NumberHelper::combineCellPrefix($prefix, $number)
Check of the string is in the current route name
RouteHelper::currentRouteContains($string);
Get the number of sms messages from the string
SmsHelper::multipart_count($str);
Helper functions related to the spatie media package for managing files
https://spatie.be/docs/laravel-medialibrary/v10/introduction
This will get the first character of each word and capitalise them and only return first letter/s
StringHelper::initials($str, bool $upperCase = true);
This will capitalise first character of each word and return the string
StringHelper::capitaliseFirstChar($string);
Removed all white spaces and special characters
StringHelper::clean($string, string $delimiter = '-', bool $toLower = false, bool $removeSpecialChars = true);
This will generate a random password
StringHelper::generatePassword($length = 15, $count = 1, $characters = 'lower_case,upper_case,numbers,special_symbols');
This will mask a string with relevant characters
StringHelper::mask($string, string $maskingCharacter = '*', int $padLeft = 4, int $padRight = 4));
Transform db column name to human-readable
StringHelper::dbColumnHumanReadable($string_array);
Transform db column name to human-readable relation
StringHelper::dbColumnRelation($string_array);
Return a list of all special characters
StringHelper::specialCharacters();
Include these traits in any of your classes
This is a helper function to the spatie activity log package
https://spatie.be/docs/laravel-activitylog/v4/introduction
use ActivityHelper;
$thia->log(string $channel, string $description, $preformedOn = null, $causedBy = null, array $properties = []);
This is a helper for the WireUI notifications to easily fire a notification from any livewire class. https://v1.wireui.dev/
use AlertHelper;
$this->alert($title, $text...);
$this->alertUpdated();
$this->alertCreated();
$this->alertDeleted();
etc
Use the trait in your database models instead of having to write the boilerplate code multiple times
use DropdownSchema;
$this->table('categories');
Use the trait in your database models to allow access to composite primary keys
use HasCompositePrimaryKey;
$this->find($ids, $columns = ['*']);
$this->setKeysForSaveQuery($query);
Us this trait for password strength progress bar.
use PasswordStrength;
Us this trait for standard password validation.
use PasswordValidationRules;
This will fave all your model data to uppercase
use SaveToUpper;
This will force all empty string to be null instead of empty
use SetNullOnEmpty;
$this->setNullOnEmpty($input);
This will toggle enable or disable triggers in the relevant database table
use TriggerHelper;
$this->switchDatabaseTrigger($enable = true, $table = null, $trigger = null, string $connection = 'sqlsrv');
This is a helper for the livewire powergrid package on for the pagination. https://livewire-powergrid.com/
use TableHelper;
Run pest testing
composer test
Run phpstan code analysis
composer analyse
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.