ahs-composer/laravel-helpers
最新稳定版本:v1.0.5
Composer 安装命令:
composer require ahs-composer/laravel-helpers
包简介
A collection of helper functions for Laravel
README 文档
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");
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-05-28