propaysystems / utilities
A set of helper utilities and traits
Installs: 1 840
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: ^8.1
- bjeavons/zxcvbn-php: ^1.0
- illuminate/contracts: ^9.0|^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
Propay Utilities
A set of helper utilities and traits to common functions we use everyday and across all our systems.
Requirements
PHP 8.1+
Laravel 9+
Installation
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"
Features
Helpers
-- Database Helper --
Clears all data and reset auto increment on given table.
DatabaseHelper::resetTable($table);
-- Date Helper --
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);
-- File Helper --
This will get the human-readable format of the bytes you pass in
FileHelper::formatBytes($bytes, $precision = 2);
-- Http Helper --
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();
-- Id Number Helper --
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);
-- Number Helper --
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)
-- Route Helper --
Check of the string is in the current route name
RouteHelper::currentRouteContains($string);
-- SMS Helper --
Get the number of sms messages from the string
SmsHelper::multipart_count($str);
-- Spatie Media Helper --
Helper functions related to the spatie media package for managing files
https://spatie.be/docs/laravel-medialibrary/v10/introduction
-- String Helper --
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();
Traits
Include these traits in any of your classes
-- Activity Helper Trait --
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 = []);
-- TableHelper Trait --
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
-- Dropdown Schema Trait --
Use the trait in your database models instead of having to write the boilerplate code multiple times
use DropdownSchema; $this->table('categories');
-- Composite Primary Key Trait --
Use the trait in your database models to allow access to composite primary keys
use HasCompositePrimaryKey; $this->find($ids, $columns = ['*']); $this->setKeysForSaveQuery($query);
-- Password Strength Trait --
Us this trait for password strength progress bar.
use PasswordStrength;
-- Password Validation Trait --
Us this trait for standard password validation.
use PasswordValidationRules;
-- Save to uppercase Trait --
This will fave all your model data to uppercase
use SaveToUpper;
-- Set null on empty Trait --
This will force all empty string to be null instead of empty
use SetNullOnEmpty; $this->setNullOnEmpty($input);
-- Toggle triggers Trait --
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');
-- TableHelper Trait --
This is a helper for the livewire powergrid package on for the pagination. https://livewire-powergrid.com/
use TableHelper;
Testing
Run pest testing
composer test
Run phpstan code analysis
composer analyse
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.