PHPackages                             abdullah-mateen/laravel-helping-material - 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. abdullah-mateen/laravel-helping-material

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

abdullah-mateen/laravel-helping-material
========================================

Laravel helper functions and general helping material

v3.0.1(2mo ago)0187MITPHPPHP ^8.1

Since Feb 15Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/AbdullahMateen/laravel-helping-material)[ Packagist](https://packagist.org/packages/abdullah-mateen/laravel-helping-material)[ RSS](/packages/abdullah-mateen-laravel-helping-material/feed)WikiDiscussions 3.x Synced today

READMEChangelog (10)Dependencies (8)Versions (17)Used By (0)

[![Laravel Helping Material](./images/banner.png)](./images/banner.png)

[![Total Downloads](https://camo.githubusercontent.com/38676885d9d14070c23601031c05743c5cc3b7124effe4aaed1fac532b4ff0a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616264756c6c61682d6d617465656e2f6c61726176656c2d68656c70696e672d6d6174657269616c2e737667)](https://packagist.org/packages/abdullah-mateen/laravel-helping-material)[![GitHub issues](https://camo.githubusercontent.com/c04770870f80e8469d946e1e9fc3f55a10b67271d8690712da285db72c3c5182/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f416264756c6c61684d617465656e2f6c61726176656c2d68656c70696e672d6d6174657269616c2e737667)](https://github.com/AbdullahMateen/laravel-helping-material/issues)[![GitHub stars](https://camo.githubusercontent.com/fa192448d76e45c4a11dceca60863e2f3e255279be68a934a0afad414b8e6b20/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f416264756c6c61684d617465656e2f6c61726176656c2d68656c70696e672d6d6174657269616c2e7376673f7374796c653d736f6369616c)](https://github.com/AbdullahMateen/laravel-helping-material)[![GitHub forks](https://camo.githubusercontent.com/c26a0ec6b7aaef6c86fd0fc56106ef969b1939188ae4bd04b2d9f999543d71b9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f416264756c6c61684d617465656e2f6c61726176656c2d68656c70696e672d6d6174657269616c2e7376673f7374796c653d736f6369616c)](https://github.com/AbdullahMateen/laravel-helping-material/network)[![GitHub watchers](https://camo.githubusercontent.com/9a4ac859da1540da3f9cff850d1de1428d4954af4c518c0a9059cc900522794f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f416264756c6c61684d617465656e2f6c61726176656c2d68656c70696e672d6d6174657269616c2e7376673f7374796c653d736f6369616c)](https://github.com/AbdullahMateen/laravel-helping-material/watchers)

Laravel Helping Material
========================

[](#laravel-helping-material)

Laravel Helping Material is a Laravel utility package that bundles common helpers, enums, model traits, API response helpers, middleware, resources, and a class-based media upload service.

It is designed for Laravel applications that need reusable project scaffolding plus simple media storage flows such as profile images, documents, temporary uploads, and database-backed media records.

Table Of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Publishing Files](#publishing-files)
- [Artisan Commands](#artisan-commands)
- [Helper Functions](#helper-functions)
- [Upgrade Guide](#upgrade-guide)
- [Enums](#enums)
- [Models](#models)
- [Middleware](#middleware)
- [Blade Directives](#blade-directives)
- [Response Macros](#response-macros)
- [Media Service](#media-service)
- [Interfaces](#interfaces)
- [Resources](#resources)
- [Validation Rules](#validation-rules)
- [Examples](#examples)
- [Author](#author)
- [License](#license)

Features
--------

[](#features)

- Helper functions for application config, auth, files, dates, numbers, strings, arrays, pagination, XML, and impersonation.
- PHP backed enums for user, media, temporal, notification, boolean, and status values.
- Model base classes and model traits for common Laravel model behavior.
- `authorize` middleware for role-level route authorization.
- API response trait and response macros for consistent JSON responses.
- Blade directives for displaying validation errors.
- Class-based `MediaService` plus typed services: `ImageService`, `AudioService`, `VideoService`, `DocumentService`, and `ArchiveService`.
- Optional publish command for copying config, enums, helpers, middleware, migrations, models, resources, services, and traits into your app.

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

[](#requirements)

- PHP `^8.1`.
- Laravel `^10.0`, `^11.0`, `^12.0`, or `^13.0`.
- PHP extensions: `curl`, `fileinfo`, `gd`, `intl`, `json`, and `simplexml`.
- `intervention/image` `^3.3`.

The package is compatible with PHP 8.4 and PHP 8.5, and the test suite has been verified on PHP 8.5.

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

[](#installation)

Install the package with Composer:

```
composer require abdullah-mateen/laravel-helping-material
```

Laravel package auto-discovery registers the service provider automatically. If package discovery is disabled in your project, register the provider manually:

```
// config/app.php
'providers' => [
    AbdullahMateen\LaravelHelpingMaterial\LaravelHelpingMaterialServiceProvider::class,
],
```

After installation, publish the storage symlink if you store public files:

```
php artisan storage:link
```

Configuration
-------------

[](#configuration)

Publish the config when you need to customize models, strict mode, storage, or media extensions:

```
php artisan vendor:publish --tag=laravel-helping-material-config
```

The config file is published to `config/lhm.php`.

Important config keys:

```
return [
    'api' => [
        'response_keys' => [
            'snake_case' => env('LHM_SNAKE_CASE', false),
        ],
    ],

    'models' => [
        'should_be_strict' => env('LHM_SHOULD_BE_STRICT', false),
        'user' => App\Models\User::class,
    ],

    'storage' => [
        'folder' => env('STORAGE_FOLDER', 'storage'),
        'shared' => [
            'enabled' => env('SHARED_STORAGE', false),
            'path' => env('SHARED_STORAGE_PATH', null),
        ],
    ],

    'media_service' => [
        'model' => AbdullahMateen\LaravelHelpingMaterial\Models\Media::class,
        'media_disk_enum' => AbdullahMateen\LaravelHelpingMaterial\Enums\Media\MediaDiskEnum::class,
        'extensions' => [
            'image' => ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'svg', 'webp'],
            'audio' => ['mp3', 'aac', 'ogg', 'flac', 'alac', 'wav', 'aiff', 'dsd', 'pcm'],
            'video' => ['mp3', 'mp4', 'mov', 'webm'],
            'document' => ['pdf', 'doc', 'docx', 'csv', 'xlx', 'txt', 'pptx', 'divx'],
            'archive' => ['7z', 's7z', 'apk', 'jar', 'rar', 'tar.gz', 'tgz', 'tarZ', 'tar', 'zip', 'zipx'],
        ],
    ],
];
```

Publishing Files
----------------

[](#publishing-files)

The package supports Laravel vendor publishing and its own interactive publish command.

Publish config only:

```
php artisan vendor:publish --tag=laravel-helping-material-config
```

Publish migrations only:

```
php artisan vendor:publish --tag=laravel-helping-material-migrations
```

Run the interactive package publisher:

```
php artisan lhm:publish
```

`lhm:publish` shows a menu and lets you publish one or more groups.

OptionWhat it publishesDestination`All`Every supported publish groupMultiple paths`Config``lhm.php` config`config/lhm.php``Enums`media and user enum stubs`app/Enums``Exceptions`API response exception handler stub`app/Exceptions``Helpers`custom helper file stub`app/Helpers/custom.php``Middlewares`authorization middleware stub`app/Http/Middleware``Migrations`package migrations`database/migrations``Models`extended model and media model stubs`app/Models``Resources`Sass utility resources`resources/sass``Services`app media service extension stub`app/Services/Media``Traits`user notification trait stub`app/Traits`Artisan Commands
----------------

[](#artisan-commands)

### `php artisan lhm:publish`

[](#php-artisan-lhmpublish)

Publishes package stubs and resources into your application through an interactive checklist.

```
php artisan lhm:publish
```

Use this when you want local editable copies of package files.

### `php artisan make:lhm-enum`

[](#php-artisan-makelhm-enum)

Creates an enum using the package enum stubs. It extends Laravel's enum generator.

```
php artisan make:lhm-enum User/StatusEnum
php artisan make:lhm-enum User/RoleEnum --int
php artisan make:lhm-enum Billing/InvoiceStatusEnum --string
```

### `php artisan make:lhm-model`

[](#php-artisan-makelhm-model)

Creates a model using the package model stub. It extends Laravel's model generator.

```
php artisan make:lhm-model Product
php artisan make:lhm-model Product -mfs
```

Helper Functions
----------------

[](#helper-functions)

All package helper functions are documented in [HELPER\_FUNCTIONS.md](./HELPER_FUNCTIONS.md).

The package autoloads its own helpers through Composer. If you publish your own helper file with `php artisan lhm:publish`, add that custom file to your application `composer.json`:

```
{
  "autoload": {
    "files": [
      "app/Helpers/custom.php"
    ]
  }
}
```

Then refresh Composer autoloading:

```
composer dump-autoload
```

Basic helper examples:

```
$user = auth_user();
$title = webpage_title('Dashboard');
$route = route_url_to_name('https://example.test/dashboard');
$formatted = display_number(12500.5);
```

Upgrade Guide
-------------

[](#upgrade-guide)

Upgrading from `2.x` to `3.x` requires reviewing media service usage and any published overrides. See [UPGRADE-2.x-TO-3.x.md](./UPGRADE-2.x-TO-3.x.md).

Enums
-----

[](#enums)

The package includes reusable PHP enums.

NamespaceEnums`AbdullahMateen\LaravelHelpingMaterial\Enums``BooleanEnum`, `StatusEnum``AbdullahMateen\LaravelHelpingMaterial\Enums\Media``MediaDiskEnum`, `MediaTypeEnum``AbdullahMateen\LaravelHelpingMaterial\Enums\Notification``StatusEnum``AbdullahMateen\LaravelHelpingMaterial\Enums\Temporal``DayEnum`, `MonthEnum`, `TimeUnitEnum``AbdullahMateen\LaravelHelpingMaterial\Enums\User``AccountStatusEnum`, `GenderEnum`, `RoleEnum`, `TitleEnum`Example enum casts:

```
use AbdullahMateen\LaravelHelpingMaterial\Enums\User\AccountStatusEnum;
use AbdullahMateen\LaravelHelpingMaterial\Enums\User\GenderEnum;
use AbdullahMateen\LaravelHelpingMaterial\Enums\User\RoleEnum;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    protected function casts(): array
    {
        return [
            'role' => RoleEnum::class,
            'gender' => GenderEnum::class,
            'status' => AccountStatusEnum::class,
        ];
    }
}
```

Example enum helpers:

```
RoleEnum::Customer->value;
RoleEnum::toArray();
RoleEnum::toFullArray();
RoleEnum::fromName('Customer');
```

Models
------

[](#models)

The package includes:

- `ExtendedModel`: a base Eloquent model with common package traits.
- `AuthenticatableExtendedModel`: a base authenticatable model with common package traits.
- `Media`: the default media database model.
- `Notification`: the default notification model.

Use the included `Media` model by default, or override it in `config/lhm.php`:

```
'media_service' => [
    'model' => App\Models\Media::class,
],
```

If you publish the model stubs, you can customize the app-level models:

```
php artisan lhm:publish
# choose Models
```

Middleware
----------

[](#middleware)

The package registers `authorize` middleware automatically.

```
use AbdullahMateen\LaravelHelpingMaterial\Enums\User\RoleEnum;
use Illuminate\Support\Facades\Route;

Route::get('/admin', AdminController::class)
    ->middleware('authorize:1001,3001');

Route::get('/staff', StaffController::class)
    ->middleware('authorize:' . RoleEnum::column('value', 'admins', true));
```

If you publish and customize the middleware, register your custom alias in your Laravel application and use that alias instead.

Blade Directives
----------------

[](#blade-directives)

The service provider registers two validation helper directives.

```

@showError('email')
```

For multiple fields:

```

@showError('password,password_confirmation')
```

Response Macros
---------------

[](#response-macros)

The package registers response macros for common API responses.

```
return response()->response(
    response: 200,
    message: 'Profile updated',
    data: ['user' => $user],
);

return response()->everythingOK('Saved successfully');
return response()->invalid('Invalid data provided');
return response()->unauthenticated();
return response()->loginAttemptFailed();
return response()->authNotFound();
return response()->refreshToken(['token' => $token]);
return response()->loggedIn(['user' => $user]);
return response()->loggedOut();
```

Set `LHM_SNAKE_CASE=true` when you want API response keys converted to snake\_case.

Media Service
-------------

[](#media-service)

The media service has two layers:

- `MediaService`: the full chainable service.
- Typed convenience services: `ImageService`, `AudioService`, `VideoService`, `DocumentService`, and `ArchiveService`.

Typed services validate the resolved file type before storing. For example, `ImageService` only accepts images and `DocumentService` only accepts documents.

### Storage vs Database

[](#storage-vs-database)

- `store()` writes to the filesystem only.
- `persist()` writes to the filesystem and inserts media rows in the database.
- `MediaService::store()->save($model)` gives chainable control and writes database rows.
- Passing `null` as the model stores a database row without a `mediaable` relation.

### Store A Profile Picture And Save It To DB

[](#store-a-profile-picture-and-save-it-to-db)

```
use AbdullahMateen\LaravelHelpingMaterial\Services\Media\ImageService;
use Illuminate\Http\Request;

public function updateAvatar(Request $request): array
{
    $request->validate([
        'avatar' => ['required', 'image', 'max:2048'],
    ]);

    return ImageService::persist(
        file: $request->file('avatar'),
        model: $request->user(),
        path: 'users/'.$request->user()->id.'/profile',
        filename: 'avatar',
        disk: 'public',
    );
}
```

### Store A File Without A Model

[](#store-a-file-without-a-model)

```
use AbdullahMateen\LaravelHelpingMaterial\Services\Media\DocumentService;

$result = DocumentService::store(
    file: $request->file('document'),
    path: 'uploads/documents',
    disk: 'public',
);
```

### Store A DB Row Without A Model Relation

[](#store-a-db-row-without-a-model-relation)

```
$result = DocumentService::persist(
    file: $request->file('document'),
    model: null,
    path: 'unattached/documents',
    disk: 'public',
);
```

### Store Multiple Files

[](#store-multiple-files)

```
use AbdullahMateen\LaravelHelpingMaterial\Services\Media\MediaService;

$media = app(MediaService::class)
    ->filesStore($request->file('attachments'), 'tickets/'.$ticket->id, null, 'public')
    ->save($ticket);

$data = $media->getData()->values()->all();
$ids = $media->getIds(false);
```

### Generate An Image Thumbnail

[](#generate-an-image-thumbnail)

```
$media = ImageService::service($request->file('avatar'))
    ->thumbnail(fn ($image) => $image->scale(width: 320))
    ->store('users/'.$user->id.'/profile', 'avatar', 'public')
    ->save($user);
```

### Store Temporarily, Then Move Later

[](#store-temporarily-then-move-later)

```
$temp = DocumentService::persist(
    file: $request->file('document'),
    model: null,
    path: 'temporary/documents',
    disk: 'public',
);

$media = app(MediaService::class)
    ->model($user)
    ->move(
        values: $temp['ids'],
        fromDisk: 'public',
        fromPath: 'temporary/documents',
        toDisk: 'public',
        toPath: 'users/'.$user->id.'/documents',
        column: 'id',
    );
```

### Move From One Disk To Another

[](#move-from-one-disk-to-another)

```
$media = app(MediaService::class)
    ->model($user)
    ->move(
        values: [1, 2, 3],
        fromDisk: 'public',
        fromPath: 'users/'.$user->id.'/documents',
        toDisk: 's3',
        toPath: 'users/'.$user->id.'/documents',
        column: 'id',
    );
```

### Replace Existing Media

[](#replace-existing-media)

```
$media = DocumentService::service($request->file('document'))
    ->store('replacement/documents', null, 'public')
    ->update($mediaId, 'public', 'id');
```

### Delete Media

[](#delete-media)

```
// Delete database rows and physical files.
app(MediaService::class)->destroy([1, 2, 3], 'id', true);

// Delete database rows only.
app(MediaService::class)->destroy([1, 2, 3], 'id', false);

// Delete a physical file only.
app(MediaService::class)->remove('report.pdf', 'uploads/documents', 'public');
```

### Typed Service Quick Reference

[](#typed-service-quick-reference)

```
ImageService::store($file, 'images', null, 'public');
AudioService::store($file, 'audio', null, 'public');
VideoService::store($file, 'videos', null, 'public');
DocumentService::store($file, 'documents', null, 'public');
ArchiveService::store($file, 'archives', null, 'public');
```

See the full scenario file at [examples/media-service-api-examples.php](./examples/media-service-api-examples.php).

Interfaces
----------

[](#interfaces)

`ColorsInterface` exposes color class and color code constants for consistent enum/UI color handling.

```
use AbdullahMateen\LaravelHelpingMaterial\Interfaces\ColorsInterface;

class Badge implements ColorsInterface
{
    public function className(): string
    {
        return 'bg-'.self::SUCCESS_CLASS;
    }

    public function colorCode(): string
    {
        return self::SUCCESS;
    }
}
```

Resources
---------

[](#resources)

The package ships Sass utilities for colors, spacing, sizing, borders, and positioning. Publish them with:

```
php artisan lhm:publish
# choose Resources
```

They are copied to `resources/sass`.

Validation Rules
----------------

[](#validation-rules)

The package includes `AbdullahMateen\LaravelHelpingMaterial\Rules\Throttle`.

```
use AbdullahMateen\LaravelHelpingMaterial\Rules\Throttle;

$request->validate([
    'email' => ['required', 'email', new Throttle()],
]);
```

Examples
--------

[](#examples)

- Full media API examples: [examples/media-service-api-examples.php](./examples/media-service-api-examples.php)
- Full helper reference: [HELPER\_FUNCTIONS.md](./HELPER_FUNCTIONS.md)

Author
------

[](#author)

**[Abdullah Mateen](https://github.com/AbdullahMateen/laravel-helping-material)** -

License
-------

[](#license)

The MIT License (MIT) 2024 - [Abdullah Mateen](https://github.com/AbdullahMateen/laravel-helping-material). See [LICENSE](./LICENSE) for details.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance87

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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 ~57 days

Recently: every ~93 days

Total

15

Last Release

64d ago

Major Versions

1.x-dev → v2.0.02025-03-06

v2.0.6 → v3.0.02026-04-26

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22071476?v=4)[Abdullah Mateen](/maintainers/AbdullahMateen)[@AbdullahMateen](https://github.com/AbdullahMateen)

---

Top Contributors

[![AbdullahMateen](https://avatars.githubusercontent.com/u/22071476?v=4)](https://github.com/AbdullahMateen "AbdullahMateen (95 commits)")[![DevMateen101](https://avatars.githubusercontent.com/u/106698097?v=4)](https://github.com/DevMateen101 "DevMateen101 (6 commits)")

---

Tags

laravelhelpers

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/abdullah-mateen-laravel-helping-material/health.svg)

```
[![Health](https://phpackages.com/badges/abdullah-mateen-laravel-helping-material/health.svg)](https://phpackages.com/packages/abdullah-mateen-laravel-helping-material)
```

###  Alternatives

[laravolt/avatar

Turn name, email, and any other string into initial-based avatar or gravatar.

2.0k5.8M38](/packages/laravolt-avatar)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[rappasoft/laravel-helpers

Laravel Helpers for Non-Laravel Projects

277681.9k22](/packages/rappasoft-laravel-helpers)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1235.9k20](/packages/fleetbase-core-api)[symfony/ux-cropperjs

Cropper.js integration for Symfony

19346.6k3](/packages/symfony-ux-cropperjs)[transprime-research/piper

PHP Pipe method execution with values from chained method executions

174.7k2](/packages/transprime-research-piper)

PHPackages © 2026

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