PHPackages                             helperfunctions/helperfunctions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. helperfunctions/helperfunctions

ActiveLibrary

helperfunctions/helperfunctions
===============================

A comprehensive collection of helper functions for PHP/Laravel applications including API calls, calculations, date operations, and more.

00PHP

Since Nov 3Pushed 6mo agoCompare

[ Source](https://github.com/AamirAnwar3311/My-Own-Custom-Functions)[ Packagist](https://packagist.org/packages/helperfunctions/helperfunctions)[ RSS](/packages/helperfunctions-helperfunctions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

HelperFunctions
===============

[](#helperfunctions)

A comprehensive collection of helper functions for PHP/Laravel applications including API calls, calculations, date operations, string manipulation, file handling, array utilities, and validation helpers.

[![Latest Stable Version](https://camo.githubusercontent.com/f6ea296e3908db50b4b3877923fac836e0485fc17b185cf2f13ac978986d8744/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68656c70657266756e6374696f6e732f68656c70657266756e6374696f6e732e737667)](https://packagist.org/packages/helperfunctions/helperfunctions)[![Total Downloads](https://camo.githubusercontent.com/d3bcf05b35ec2c5f3f180cd6313252aa53db8558d8313754e05381cda6630afe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68656c70657266756e6374696f6e732f68656c70657266756e6374696f6e732e737667)](https://packagist.org/packages/helperfunctions/helperfunctions)[![License](https://camo.githubusercontent.com/810da2b75f41a5801e460723ec7fd7e938569a5adbbe09391da0af063739069c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68656c70657266756e6374696f6e732f68656c70657266756e6374696f6e732e737667)](https://packagist.org/packages/helperfunctions/helperfunctions)

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require helperfunctions/helperfunctions
```

### Laravel

[](#laravel)

The package will auto-register the service provider. If you're using Laravel 5.5+, the service provider will be automatically discovered.

For older Laravel versions, add the service provider to `config/app.php`:

```
'providers' => [
    // ...
    HelperFunctions\Helpers\HelperFunctionsServiceProvider::class,
],
```

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- Laravel 7.0 or higher (optional for standalone use)
- Guzzle HTTP Client
- Carbon

Features
--------

[](#features)

### ✨ Helper Classes

[](#-helper-classes)

- **ApiHelper** - Make HTTP requests easily
- **MathHelper** - Mathematical operations and calculations
- **StringHelper** - String manipulation utilities
- **DateHelper** - Date and time operations
- **FileHelper** - File upload and management
- **ArrayHelper** - Array manipulation utilities
- **ValidationHelper** - Input validation helpers

Usage
-----

[](#usage)

### API Helper

[](#api-helper)

Make HTTP requests to external APIs:

```
use HelperFunctions\Helpers\ApiHelper;

// Make a GET request
$response = ApiHelper::hitApi(
    'GET',
    'https://api.example.com/users',
    ['page' => 1],  // query parameters
    [],             // body (empty for GET)
    ['Authorization' => 'Bearer token']  // headers
);

// Using Laravel Http facade helpers
$response = ApiHelper::get('https://api.example.com/users', ['page' => 1]);
$response = ApiHelper::post('https://api.example.com/users', ['name' => 'John']);
$response = ApiHelper::put('https://api.example.com/users/1', ['name' => 'Jane']);
$response = ApiHelper::delete('https://api.example.com/users/1');

// Parse JSON response
$data = $response->json();
```

### Math Helper

[](#math-helper)

Perform mathematical operations:

```
use HelperFunctions\Helpers\MathHelper;

// Basic calculations
$sum = MathHelper::calculate(10, 5, 'sum');           // 15
$diff = MathHelper::calculate(10, 5, 'subtract');     // 5
$product = MathHelper::calculate(10, 5, 'multiply');  // 50
$quotient = MathHelper::calculate(10, 5, 'divide');   // 2

// Float calculations
$result = MathHelper::calculateFloat(10.5, 2.3, 'sum');

// Calculate commission
$commission = MathHelper::calculateCommission(1000, 15); // 150.0

// Random numbers
$random = MathHelper::randomInt(1, 100);
$randomFloat = MathHelper::randomFloat(0.0, 1.0);

// Format numbers
$formatted = MathHelper::formatNumber(1234567.89); // "1,234,567.89"
```

### String Helper

[](#string-helper)

String manipulation utilities:

```
use HelperFunctions\Helpers\StringHelper;

// Create URL-friendly slug
$slug = StringHelper::slug('Hello World!'); // "hello-world"

// Generate random string
$random = StringHelper::randomString(16);

// Generate OTP
$otp = StringHelper::generateOTP(6);

// Mask sensitive data
$masked = StringHelper::mask('1234567890', 2, 4); // "12****90"
$maskedEmail = StringHelper::maskEmail('john@example.com'); // "jo**@***le.com"

// Truncate text
$short = StringHelper::truncate('Long text here', 10); // "Long text ..."

// Check if JSON
$isJson = StringHelper::isJson('{"name":"John"}'); // true

// Case conversion
$snake = StringHelper::camelToSnake('camelCase');  // "camel_case"
$camel = StringHelper::snakeToCamel('snake_case'); // "SnakeCase"

// Get initials
$initials = StringHelper::getInitials('John Doe'); // "JD"
```

### Date Helper

[](#date-helper)

Date and time operations:

```
use HelperFunctions\Helpers\DateHelper;

// Check expiry
$status = DateHelper::checkExpiry('2024-01-01', '2024-12-31'); // 'active', 'expired', or 'not_started'

// Format dates
$formatted = DateHelper::formatDate('2024-12-25', 'Y-m-d');

// Human-readable difference
$diff = DateHelper::diffForHumans('2024-01-01'); // "1 year ago"

// Get age
$age = DateHelper::getAge('1990-05-15'); // 34

// Date checks
$isPast = DateHelper::isPast('2023-01-01');    // true
$isFuture = DateHelper::isFuture('2025-01-01'); // true
$isToday = DateHelper::isToday('2024-12-20');  // depends on current date

// Date arithmetic
$future = DateHelper::addDays('2024-01-01', 30);
$past = DateHelper::subDays('2024-01-01', 30);

// Days between dates
$days = DateHelper::daysBetween('2024-01-01', '2024-12-31'); // 364

// Start and end of day
$start = DateHelper::startOfDay('2024-12-20');
$end = DateHelper::endOfDay('2024-12-20');

// Date range
$dates = DateHelper::dateRange('2024-01-01', '2024-01-07');
```

### File Helper

[](#file-helper)

File upload and management:

```
use HelperFunctions\Helpers\FileHelper;
use Illuminate\Http\UploadedFile;

// Upload image
$path = FileHelper::uploadImage($file, 'images/products');

// Upload any file
$path = FileHelper::uploadFile($file, 'uploads/documents');

// Delete file
FileHelper::deleteFile('images/products/example.jpg');

// Get file information
$size = FileHelper::getFileSize('path/to/file.txt'); // "1.5 MB"
$extension = FileHelper::getExtension('image.jpg');  // "jpg"
$name = FileHelper::getNameWithoutExtension('image.jpg'); // "image"

// Validate file
$valid = FileHelper::validateFileType($file, ['jpg', 'png', 'gif']);
$validSize = FileHelper::validateFileSize($file, 2048); // 2048 KB

// File operations
FileHelper::createDirectory('uploads/temp');
$content = FileHelper::readFile('path/to/file.txt');
FileHelper::writeFile('path/to/file.txt', 'content');
FileHelper::copyFile('source.txt', 'destination.txt');
FileHelper::moveFile('old.txt', 'new.txt');
```

### Array Helper

[](#array-helper)

Array manipulation utilities:

```
use HelperFunctions\Helpers\ArrayHelper;

// Check if associative
$isAssoc = ArrayHelper::isAssociative(['name' => 'John', 'age' => 30]); // true

// Get value with default
$value = ArrayHelper::get($array, 'key', 'default');

// Dot notation access
$value = ArrayHelper::dotGet($array, 'user.profile.email');

// Set value with dot notation
$array = ArrayHelper::set([], 'user.profile.name', 'John');

// Flatten multi-dimensional array
$flat = ArrayHelper::flatten(['a' => ['b' => 'c']]); // ['c']

// Group by key
$grouped = ArrayHelper::groupBy($users, 'role');

// Pluck values
$emails = ArrayHelper::pluck($users, 'email');

// Remove duplicates
$unique = ArrayHelper::unique([1, 2, 2, 3]); // [1, 2, 3]

// Chunk array
$chunks = ArrayHelper::chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]

// Random elements
$random = ArrayHelper::random([1, 2, 3, 4, 5], 2);

// Convert to object
$object = ArrayHelper::toObject(['name' => 'John']);

// First and last
$first = ArrayHelper::first([1, 2, 3]); // 1
$last = ArrayHelper::last([1, 2, 3]);   // 3
```

### Validation Helper

[](#validation-helper)

Input validation utilities:

```
use HelperFunctions\Helpers\ValidationHelper;

// Validate email
$valid = ValidationHelper::isValidEmail('john@example.com'); // true

// Validate URL
$valid = ValidationHelper::isValidUrl('https://example.com'); // true

// Validate IP
$valid = ValidationHelper::isValidIp('192.168.1.1'); // true

// Validate phone
$valid = ValidationHelper::isValidPhone('+1234567890'); // true

// Validate credit card (Luhn algorithm)
$valid = ValidationHelper::isValidCreditCard('4111111111111111'); // true

// Validate password strength
$result = ValidationHelper::validatePassword('MyP@ssw0rd', 8, true, true, true, true);
if ($result['valid']) {
    echo "Password is valid";
} else {
    print_r($result['errors']);
}

// Validate date format
$valid = ValidationHelper::isValidDateFormat('2024-12-25', 'Y-m-d'); // true

// Validate range
$valid = ValidationHelper::isValidRange(50, 1, 100); // true

// Validate string length
$valid = ValidationHelper::isValidLength('hello', 3, 10); // true

// Type checks
$alpha = ValidationHelper::isAlphaOnly('Hello World'); // true
$alnum = ValidationHelper::isAlphanumeric('Hello123'); // true
$numeric = ValidationHelper::isNumeric('12345');       // true
$base64 = ValidationHelper::isValidBase64('SGVsbG8='); // true
```

Laravel Service Container
-------------------------

[](#laravel-service-container)

You can also access helpers via Laravel's service container:

```
$apiHelper = app('helper.api');
$mathHelper = app('helper.math');
$stringHelper = app('helper.string');
$dateHelper = app('helper.date');
$fileHelper = app('helper.file');
$arrayHelper = app('helper.array');
$validationHelper = app('helper.validation');
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

License
-------

[](#license)

This package is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Support
-------

[](#support)

For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/AamirAnwar3311/My-Own-Custom-Functions).

Author
------

[](#author)

**HelperFunctions Contributors**

- GitHub: [@AamirAnwar3311](https://github.com/AamirAnwar3311)
- Homepage:

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for more information on what has changed recently.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance46

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f59242de158dcb939ca38587b572c90c038e9d0e5e2a58b73f5037e8d8995916?d=identicon)[AamirAnwar3311](/maintainers/AamirAnwar3311)

---

Top Contributors

[![AamirAnwar3311](https://avatars.githubusercontent.com/u/72580218?v=4)](https://github.com/AamirAnwar3311 "AamirAnwar3311 (3 commits)")

### Embed Badge

![Health badge](/badges/helperfunctions-helperfunctions/health.svg)

```
[![Health](https://phpackages.com/badges/helperfunctions-helperfunctions/health.svg)](https://phpackages.com/packages/helperfunctions-helperfunctions)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
