ahs-composer / laravel-helpers
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
Requires
- php: >=7.4
- illuminate/support: ^8.0|^9.0|^10.0
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");