Other Features
Helpers
Custom global functions to make your life easier.
uses custom helper functions app/helpers.php
to improve your quality of development.
Available methods
module_enabled()
Check if module is enabled.
if (module_enabled('blog')) {
dd('Blog is enabled');
} else {
dd('Blog is disabled');
}
email_verification_enabled()
Check if User must verify email upon registration.
if (email_verification_enabled()) {
dd('Email verification is required');
}
convert_keys_to_camel_case()
Convert all PHP array keys such as foo_bar
to fooBar
to follow Vue naming convention.
$data = [
'first_name' => 'Tony',
'last_name' => 'Stark',
'nickname' => 'Iron Man',
];
$data = convert_keys_to_camel_case($data);
// $data content after conversion
// [
// 'firstName' => 'Tony',
// 'lastName' => 'Stark',
// 'nickname' => 'Iron Man',
// ];
get_country_list()
Get list of all countries as array using REST Countries API.
$countries = get_country_list();
// [
// 'hr' => [
// 'name' => 'Croatia',
// 'flag' => 'hr',
// ],
// 'us' => [
// 'name' => 'United States of America',
// 'flag' => 'us',
// ],
// ];
$countries = get_country_list('cca2');
// ['hr', 'us']
$countries = get_country_list('name.common');
// ['Croatia', 'United States of America']
get_timezones()
Get list of all available timezones as array.
$timezones = get_timezones();
// ...
$timezonesForCroatia = get_timezones('hr');
// ['Europe/Zagreb']
pretty_date()
Convert Carbon date to prettified format.
$date = pretty_date(now());
// ...
$date = pretty_date(now(), false);
// ...
diff_for_humans()
Convert Carbon date to human-readable format like just now, 2 hours ago, 5 months ago, etc.
$date = diff_for_humans(now());
// just now
$date = diff_for_humans(now()->take('2 hours'));
// 2 hours ago
calculate_reading_time()
Calculate reading time (for blog post content) based on number of words.
This is already implemented with Blog module.
$time = calculate_reading_time('Lots of words...');
// 10
Full docs coming soon…