πŸ“–Usage

This page explains the functions structure and examples.

circle-info

In this section, you'll find detailed information on how to use each helper provided by Helpify. If you haven't installed the package yet, make sure to follow the installation instructions first.

  1. short_url

    Shortens a given URL using the is.gd URL shortening service.

use Helpify\Helpers;

$url = 'https://www.example.com';
$shortenedURL = Helpers::short_url($url);
//---------------
$shortenedURL = short_url($url); // https://is.gd/dsUwVY" 

Parameters

  • $url (string): The URL to shorten.

Return Value

  • (string): The shortened URL.

  1. checkValidIpAddress

Checks if a given IP address is valid.

use Helpify\Helpers;
$ip = '192.168.1.1'; 

$isIPAddressValid = checkValidIpAddress($ip);
// OR
$isIPAddressValid = Helpers::checkValidIpAddress($ip);

Parameters

  • $ip (string): The IP address to check.

Return Value

  • (bool): true if the IP address is valid, false otherwise.

  1. getClientIp

Gets the client's IP address from various possible sources, such as HTTP headers and server variables.

Return Value

  • (string): The client's IP address.

  1. getClientBrowser

Gets the client's browser based on the User-Agent header.

Return Value

  • (string): The client's browser.

  1. htmlTag

Generates an HTML tag with attributes

Parameters

  • $tag (string): The tag name.

  • $attributes (array, optional): The attributes of the tag.

  • $content (string, optional): The content of the tag.

Return Value

  • (string): The generated HTML tag.

  1. getClientOs

Gets the client's operating system based on the User-Agent header.

Return Value

  • (string): The client's operating system.

  1. getClientDevice

Gets the type of device used by the client based on the User-Agent header.

Return Value

  • (string): The client's device.

  1. getClientCountry

Gets the client's country based on their IP address.

Return Value

  • (string): The client's country.

  1. activeClass

Get the CSS class for the active route.

Parameters

  • $routes (array): The routes to check for activity.

  • $output (string, optional): The output class to return if a match is found (default: "active").

Return Value

  • (string|null): The output class if the current route matches any of the provided routes, otherwise null.

  1. formatDate

Formats a date in the specified format.

Parameters

  • $format (string): The date format (e.g., 'Y-m-d H:i:s').

  • $date (\DateTimeInterface): The DateTime object to format.

Return Value

  • (string): The formatted date.

  1. truncateString

Truncates a string to a specified length and appends '...' if the string is longer than the specified length.

Parameters

  • $string (string): The string to truncate.

  • $length (int): The desired length.

Return Value

  • (string): The truncated string.

  1. generateSlug

Generates a URL-friendly slug from a given string by replacing non-alphanumeric characters with hyphens.

Parameters

  • $string (string): The string to convert to a slug.

Return Value

  • (string): The generated slug.

  1. generateRandomString

Generates a random string of a specified length.

Parameters

  • $length (int, optional): The length of the random string (default: 10).

Return Value

  • (string): The generated random string.

  1. arrayFlatten

Flattens a multi-dimensional array into a single level.

Parameters

  • $array (array): The array to flatten.

Return Value

  • (array): The flattened array.

Generates an HTML link with the target attribute set for external link

Parameters

  • $url (string): The URL of the link.

  • $text (string): The anchor text of the link.

Return Value

  • (string): The HTML link.

  1. seededShuffle

Shuffles an array using a seeded random number generator for reproducibility.

Parameters

  • $array (array): The array to shuffle.

Return Value

  • (array): The shuffled array.

  1. generateModelSlug

Generates a slug for a Laravel model instance using the specified field.

Parameters

  • $model (\Illuminate\Database\Eloquent\Model): The Eloquent model instance.

  • $field (string, optional): The field to use for generating the slug (default: 'name').

Return Value

  • (string): The generated slug.

  1. writeToEnvFile

Add or update a key-value pair in the .env file.

Parameters

  • $key (string): The key to add or update.

  • $value (string): The value to set for the key.

Return Value

  • (void)

  1. addNewLineToEnvFile

Add a new line to the .env file.

Parameters

  • $key (string): The key to add or update.

  • $value (string): The value to set for the key.

Return Value

  • (void)

  1. toCamelCase

Converts a string to camel case.

Parameters

  • $string (string): The string to convert.

Return Value

  • (string): The camel case version of the string.

Last updated

Was this helpful?