composer require mcmatters/laravel-helpers
Then run the command
php artisan vendor:publish --provider="\McMatters\Helpers\ServiceProvider"
If you prefer manual installation, then add to config/app.php
into providers
section next line:
'providers' => [
McMatters\Helpers\ServiceProvider::class,
],
Otherwise it will be autodiscovered.
Since v2.0
, you can disable all helper functions and use helper classes, if you prefer to use helper functions, you can choose what exactly section do you want to use (array
, dev
, string
, etc)
The array_first_key
function returns first key from the given array.
The array_has_with_wildcard
is analogue of function array_has
with ability to search with wildcard. Also it can search keys with dots (i.e. when you want to get some data from multiple field when validation is failed).
The array_key_by
function returns a new associative array grouped by $key
.
The array_contains
function returns true if array contains given $needle
. You can also search by array keys. This function searches only in first level of array.
The array_has_only_int_keys
function checks whether keys of given array as integer or not.
The shuffle_assoc
function works like basic shuffle
but with key preserving.
The array_change_key_case_recursive
function works like array_change_key_case
except that it works recursively.
The get_php_path
function returns path to executable php
.
The get_artisan
function return path to executable artisan
.
The run_background_command
function runs the given command in background.
The get_class_constants
function returns an array with all class constants.
The get_class_constants_start_with
function returns an array with constants which start with passed string.
The compile_sql_query
function replaces all placeholders given bindings.
The get_all_tables
function returns the list all tables with their columns.
The search_entire_database
function searches entire database. It works only with MySQL and SQL drivers.
The has_query_join_with
function determines whether query has a joined table.
The ddq
is analogue of function dd
, but uses only for database queries.
The dump
is analogue of function dd
, but without stopping the php script execution.
The is_production_environment
function checks whether the production environment is using.
The is_local_environment
function checks whether the local environment is using.
The is_testing_environment
function checks whether the testing environment is using.
The calculate_percentage
function calculates percentages.
The calculate_discount
function calculates discount.
The calculate_with_discount
function calculates price with discount.
The has_float_remainder
function checks whether the remainder of the float is not zero.
The convert_bytes
function converts bytes between any sizes.
The get_size_types
function returns the list all available size types.
The is_number_even
function checks whether the number is even.
The is_number_odd
function checks whether the number is odd.
The is_number_in_range
function checks whether the number is in a given range.
The get_model_from_query
function returns a model from a query.
The destroy_models_from_query
function destroy all models from a query. Useful when you want to delete many models with calling model's hooks.
The is_morphed_belongs_parent
function determines whether morphed model is belongs to parent.
The is_request_method_update
function checks whether the current request method is for updating.
The long_processes
function sets the maximum value of the optimal configuration for the server to perform long operations.
The get_upload_max_filesize
function returns the value of the upload_max_filesize
from php.ini
in any of the formats.
The get_post_max_size
function returns the value of the post_max_size
from php.ini
in any of the formats.
The is_max_post_size_exceeded
function checks whether is the permissible size of the value post_max_size
exceeded.
The get_max_response_code
function returns maximum available value for response code.
The str_lower
is function wrapper over Str::lower
.
The str_upper
is function wrapper over Str::upper
.
The str_ucwords
function converts a value to studly caps case with spaces.
The strpos_all
function returns all occurrences of $needle
in a $haystack
The random_bool
function returns a random boolean value.
The casting_bool
function returns casted boolean value.
The is_json
function check whether passed string is a json.
The is_uuid
function check whether passed value is a valid uuid value.
The get_base_url
function returns base url.
The get_host_url
function returns host url.
The routes_path
function returns path to routes
folder.