ahs-composer/laravel-helpers

There is no license information available for the latest version (v1.0.5) of this package.

A collection of helper functions for Laravel

Installs: 9

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/ahs-composer/laravel-helpers

v1.0.5 2024-05-28 13:34 UTC

This package is auto-updated.

Last update: 2025-12-28 17:15:45 UTC


README

A collection of helper functions for Laravel, created by Ali Haider.

Installation

You can install this package via Composer. Run the following command in your terminal:

composer require ahs-composer/laravel-helpers

Usage

Autoloading

This package utilizes PSR-4 autoloading, so make sure to add the following line to your composer.json file if it's not already present:

"autoload": {
    "psr-4": {
        "Ahs\\LaravelHelpers\\": "LaravelHelpers/src/"
    }
}

Helper Functions

The package provides the following helper functions:

  • slugify($string) : Converts a string into a URL-friendly slug.
  • truncate($string, $length = 100, $append = "..."): Truncates a string to a specified length and appends a suffix.
  • camelCase($string): Converts a string to camelCase.
  • array_flatten($array): Flattens a multi-dimensional array into a single-dimensional array.
  • array_key_exists_recursive($key, $array): Checks if a key exists in a multi-dimensional array.
  • format_date($date, $format = 'Y-m-d H:i:s'): Formats a date string into a specified format.
  • carbon_date($date = null): Returns a Carbon date instance for a given date or the current date.
  • current_url(): Returns the current URL.
  • url_with_params($url, $params = []): Constructs a URL with query parameters.
  • file_size_formatted($path): Formats a file size into a human-readable format.
  • env_value($key, $default = null): Retrieves an environment variable's value.
  • generate_random_string($length = 16): Generates a random string of a specified length.

Example

Here's an example of how you can use the helper functions:

use Ahs\LaravelHelpers\Helpers;

// Example usage
$slug = Helpers::slugify("Hello World!");
$truncated = Helpers::truncate("Lorem ipsum dolor sit amet", 10);
$date = Helpers::format_date("2024-05-30", "Y-m-d");