Helpers
Custom global commands and functions to make your life easier.
Artisan commands
Super Admin
In most cases, you will define super admins in your seed files.
But sometimes, you will be required to add new super admin while in production. You can do it by running this command php artisan app:admin
where you will be requested to enter all the required info for your new super admin.
Route list
There is built-in command to list all your routes php artisan route:list
, but there is no quick way to list all your public-facing pages.
You can use this custom command php artisan app:routes
which will output route name and page URI for each public page. Public pages are all GET routes not protected with auth
middleware.
Idea for this command came from neccessity to prepare SEO data for each public-facing page without going manually through routes and controllers to find them.
Sync payment products
Run php artisan payments:sync-products
when you want to update payment provider’s products and prices with your pricing tables defined in config/payments.php
.
Read more about it under Payments.
Generate sitemap
Run sitemap:generate
to generate sitemap public/sitemap.xml
for your pages.
How to configure your sitemap?
Helper functions
uses custom helper functions app/helpers.php
to improve your quality of development.
module_enabled()
Check if module is enabled.
email_verification_enabled()
Check if User must verify email upon registration.
convert_keys_to_camel_case()
Convert all PHP array keys such as foo_bar
to fooBar
to follow Vue naming convention.
get_country_list()
Get list of all countries as array using REST Countries API.
get_country_name()
Get country name from code.
get_timezones()
Get list of all available timezones as array.
format_date()
Format date to desired output. It accepts three parameters: Carbon date instance, true/false to show time (true by default) and true/false to show pretty date (false by default).
You can customize your format by updating date_format
, time_format
, pretty_date_format
and pretty_time_format
in config/app.php
configuration file.
By default, pretty dates are usually used in user-facing pages, while the default date is used in data tables.
diff_for_humans()
Convert Carbon date to human-readable format like just now, 2 hours ago, 5 months ago, etc.
This is slightly improved version of built-in Carbon function diffForHumans
, which shows x seconds ago for actions made just now.
calculate_reading_time()
Calculate reading time (for blog post content) based on number of words.
This is already implemented with Blog module.
get_previous_route()
Get previous route from request. You can pass the request or it will use the current request. This is used to determine where user should be redirected after login/logout when using dynamic redirection. It can be also used for custom logging or other features where you need to track the routing.
get_excerpt()
Get a shortened text from longer content, stripped from any HTML tags. This is useful for displaying previews of content.
Acronym
comes with custom Str
helper method to create acronyms.
How to use it?
Method accepts 3 arguments:
string $string
string $delimiter = ''
int $limit = null
Source code inspired by koenhendriks.