PHPackages                             najmul-hasan-sobuj/my-helpers - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. najmul-hasan-sobuj/my-helpers

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

najmul-hasan-sobuj/my-helpers
=============================

Minimal Laravel helper package supporting Laravel 9 to 13

v1.0.5(1mo ago)02MITPHPPHP ^8.0

Since Mar 17Pushed 1mo agoCompare

[ Source](https://github.com/Najmul-Hasan-Sobuj/my-helpers)[ Packagist](https://packagist.org/packages/najmul-hasan-sobuj/my-helpers)[ RSS](/packages/najmul-hasan-sobuj-my-helpers/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

Laravel Helpers Package
=======================

[](#laravel-helpers-package)

A collection of real-world, highly useful helper functions for Laravel projects. It is compatible with Laravel 9, 10, 11, 12, and 13.

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

[](#installation)

You can install the package via composer:

```
composer require najmul-hasan-sobuj/my-helpers
```

The package will automatically register its service provider. These functions are globally available, just like Laravel's built-in helper functions, so you don't need to import any namespace!

Publishing the Helpers (Optional)
---------------------------------

[](#publishing-the-helpers-optional)

If you would like to modify the helper functions or add your own, you can publish the `helpers.php` file to your project's `app/Helpers` directory.

Run the following command:

```
php artisan vendor:publish --tag="laravel-helpers"
```

After publishing, the file will be located at `app/Helpers/helpers.php`. You can modify it however you like.

To ensure your Laravel application loads this file, you must add it to the `autoload -> files` array in your project's `composer.json` file:

```
"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "database/factories/",
        "Database\\Seeders\\": "database/seeders/"
    },
    "files": [
        "app/Helpers/helpers.php"
    ]
},
```

Then, run:

```
composer dump-autoload
```

Because all helper functions are wrapped in `if (!function_exists('...'))`, your local application's helper functions will take precedence over the package's defaults if your autoloader loads them first.

Available Helpers
-----------------

[](#available-helpers)

### `is_active_route`

[](#is_active_route)

Returns a string (default: `'active'`) if the current route matches the given route name(s). Perfect for setting active classes in navigation menus.

```
// In a Blade template:
// Dashboard
// Users
```

### `generate_initials`

[](#generate_initials)

Generates initials from a name (e.g., "John Doe" -&gt; "JD"). Ideal for UI avatars when a user hasn't uploaded a profile picture.

```
generate_initials('John Doe'); // 'JD'
generate_initials('Alice'); // 'AL'
```

### `estimated_read_time`

[](#estimated_read_time)

Estimates the reading time in minutes for a given text. Great for blog posts and articles.

```
$content = "Long article content here...";
$minutes = estimated_read_time($content); // e.g., 5
```

### `api_response`

[](#api_response)

A standardized JSON response for APIs. Keeps your API responses consistent across controllers.

```
return api_response(true, 'User created successfully', $user, 201);
// { "success": true, "message": "User created successfully", "data": { ... } }

return api_response(false, 'Validation failed', null, 422);
```

### `format_currency`

[](#format_currency)

Formats a number as currency.

```
format_currency(1250.5); // '$1,250.50'
format_currency(500, '€'); // '€500.00'
```

### `clean_phone_number`

[](#clean_phone_number)

Extracts only the digits from a phone number string. Extremely useful for sanitizing phone numbers before saving to the database.

```
clean_phone_number('+1 (555) 123-4567'); // '15551234567'
```

### `slugify_text`

[](#slugify_text)

Creates a URL-friendly slug from a string.

```
slugify_text('Hello Laravel 13'); // 'hello-laravel-13'
```

### `truncate_text`

[](#truncate_text)

Shortens long text to a readable preview.

```
truncate_text('This is a long article title that needs shortening', 20); // 'This is a long arti...'
```

### `human_file_size`

[](#human_file_size)

Converts bytes into a human-readable file size.

```
human_file_size(1536); // '1.5 KB'
```

### `human_time_diff`

[](#human_time_diff)

Converts a date or timestamp into a relative time string.

```
human_time_diff(now()->subHours(3)); // '3 hours ago'
```

### `generate_uuid`

[](#generate_uuid)

Generates a UUID string for records, tokens, and identifiers.

```
generate_uuid(); // '550e8400-e29b-41d4-a716-446655440000'
```

### `generate_ulid`

[](#generate_ulid)

Generates a ULID string for sortable unique identifiers.

```
generate_ulid(); // '01HZY7A4QG9F3P9JYJ8H2Y8QZ8'
```

### `estimate_ai_tokens`

[](#estimate_ai_tokens)

Estimates how many tokens a prompt or response may use.

```
estimate_ai_tokens('Write a concise product summary.'); // 8
```

### `sanitize_ai_prompt`

[](#sanitize_ai_prompt)

Normalizes text before sending it to an AI model.

```
sanitize_ai_prompt("Hello\n\nPlease summarize this."); // 'Hello Please summarize this.'
```

### `chunk_text_for_ai`

[](#chunk_text_for_ai)

Splits large text into chunks that are easier to send to a model.

```
chunk_text_for_ai(str_repeat('Laravel AI ', 1000), 2000);
```

### `extract_json_from_ai_output`

[](#extract_json_from_ai_output)

Extracts JSON from a structured AI response, including fenced code blocks.

```
extract_json_from_ai_output("```json\n{\"status\":\"ok\"}\n```");
```

Supported Laravel Versions
--------------------------

[](#supported-laravel-versions)

- Laravel 9
- Laravel 10
- Laravel 11
- Laravel 12
- Laravel 13

Supported PHP Versions
----------------------

[](#supported-php-versions)

- PHP 8.0 or higher

Releasing New Changes
---------------------

[](#releasing-new-changes)

Packagist does not read your working tree directly. After you change this package, you need to publish the change in Git and create a new version tag so Packagist can discover it.

Use this flow for every release:

1. Finish and commit your code changes.
2. Bump the package version by creating a new Git tag.
3. Push both the commit and the tag to your remote repository.
4. Wait for Packagist to sync automatically, or trigger a manual update from the package page if automatic sync is not enabled.

Packagist will automatically pick up new versions from tags that follow Semantic Versioning. Use tags like `v1.0.1`, `v1.1.0`, or `v2.0.0` for stable releases. For pre-releases, you can use tags like `v1.2.0-beta1` or `v1.2.0-RC1`.

Recommended release commands:

```
git add .
git commit -m "Release v1.0.1"
git tag v1.0.1
git push origin  --tags
```

If your GitHub account is connected to Packagist, pushes usually sync automatically. If not, open the package page on Packagist and click the update button, or set up the Packagist GitHub webhook so new tags are detected faster.

Versioning tips:

- Use `patch` releases for bug fixes, like `v1.0.1`.
- Use `minor` releases for backward-compatible features, like `v1.1.0`.
- Use `major` releases for breaking changes, like `v2.0.0`.
- Keep `composer.json` free of a hardcoded `version` field so Packagist can derive versions from your tags.

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance88

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~8 days

Total

6

Last Release

59d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e7eb019837924195e8ac1403a4496dc9bda786e05375a349873415b6def9f1d4?d=identicon)[Najmul-Hasan-Sobuj](/maintainers/Najmul-Hasan-Sobuj)

---

Top Contributors

[![Najmul-Hasan-Sobuj](https://avatars.githubusercontent.com/u/46526547?v=4)](https://github.com/Najmul-Hasan-Sobuj "Najmul-Hasan-Sobuj (6 commits)")

### Embed Badge

![Health badge](/badges/najmul-hasan-sobuj-my-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/najmul-hasan-sobuj-my-helpers/health.svg)](https://phpackages.com/packages/najmul-hasan-sobuj-my-helpers)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[illuminate/pipeline

The Illuminate Pipeline package.

9348.3M267](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10533.5M991](/packages/illuminate-pagination)[illuminate/redis

The Illuminate Redis package.

8314.4M362](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

224.5M132](/packages/illuminate-cookie)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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