PHPackages                             common-my/laravel-common - 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. common-my/laravel-common

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

common-my/laravel-common
========================

A Base Common Package

0.0.8(1mo ago)029↓88.6%MITPHPPHP ^8.2

Since Feb 25Pushed 1mo agoCompare

[ Source](https://github.com/common-my/laravel-common)[ Packagist](https://packagist.org/packages/common-my/laravel-common)[ RSS](/packages/common-my-laravel-common/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (36)Versions (8)Used By (0)

Laravel Common Package
======================

[](#laravel-common-package)

A foundational common package for Laravel applications by common-my. This package provides a solid base of shared utilities, traits, interfaces, enums, and helpers meant to be reused across different projects.

Repository: [common-my/laravel-common](https://github.com/common-my/laravel-common)

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

[](#installation)

You can install the package via composer:

```
composer require common-my/laravel-common
```

Then publish the configuration file:

```
php artisan vendor:publish --tag=laravel-common-config
```

Features
--------

[](#features)

This package provides numerous foundational tools to enforce strict typing, clean error handling, and reusable logic across your Laravel stack.

### Middlewares

[](#middlewares)

- **ResponseFormat**: Automatically formats JSON success responses to include `success: true`, `data`, `__message`, and standardized `meta` for pagination.
- **InitTenancy**: Standardized tenant resolution via `X-Tenant` or `App-Id` headers. Supports auto-initialization via `stancl/tenancy`.
- **ForceJsonResponse**: Simple middleware to set the `Accept: application/json` header for all requests.

### Interfaces &amp; Enums

[](#interfaces--enums)

- **ErrorCodeInterface**: Defines a strict contract for application error codes (`title()`, `message()`, `httpCode()`, `label()`, `value()`).
- **ErrorCode Enum**: A standard set of foundational error integer cases (e.g., `UNKNOWN`, `VALIDATION_ERROR`, etc.) implementing the `ErrorCodeInterface`.

### Exceptions &amp; Error Handling

[](#exceptions--error-handling)

- **ApiException**: An exception class that strictly accepts `ErrorCodeInterface`. It provides structured data for API error responses.
- **Abort Helper**: A globally accessible `abortWithError($errorCode)` function that throws `ApiException` smoothly.

### Traits

[](#traits)

- **HasEnumArray**: Extracts an enum into a standard key-value associative array matrix.
- **HasEnumValue**: Simplifies extracting raw data from enumeration instances.

Usage
-----

[](#usage)

### Middleware Setup (Laravel 11+)

[](#middleware-setup-laravel-11)

In your `bootstrap/app.php`:

```
use CommonMy\LaravelCommon\Http\Middleware\ResponseFormat;
use CommonMy\LaravelCommon\Http\Middleware\InitTenancy;
use CommonMy\LaravelCommon\Http\Middleware\ForceJsonResponse;

return Application::configure(basePath: dirname(__DIR__))
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->prepend(InitTenancy::class);
        $middleware->append(ForceJsonResponse::class);
        $middleware->append(ResponseFormat::class);
    })
    // ...
```

### Configuration

[](#configuration)

The `config/laravel-common.php` allows you to customize tenant resolution:

```
return [
    'tenant_model' => 'App\Models\Tenant',
    'initialize_tenancy' => true, // Auto-call tenancy()->initialize()
];
```

### Exception Formatting

[](#exception-formatting)

Use the standard custom exceptions seamlessly across your application controllers or services:

```
use CommonMy\LaravelCommon\Enums\ErrorCode;

abortWithError(ErrorCode::TENANT_NOT_FOUND);
```

### Implementing Custom Error Enums

[](#implementing-custom-error-enums)

If your main application has custom error states, create your own enum implementing the `ErrorCodeInterface`:

```
namespace App\Enums;

use CommonMy\LaravelCommon\Interfaces\ErrorCodeInterface;

enum AppErrorCode: int implements ErrorCodeInterface {
    case INVENTORY_MISSING = 5001;

    public function title(): string { return 'Inventory Error'; }
    public function message(): string { return 'The requested item is out of stock.'; }
    public function httpCode(): int { return 400; }
    public function label(): string { return 'Inventory Missing'; }
    public function value(): int { return $this->value; }
}

// Still works with the base exception!
abortWithError(AppErrorCode::INVENTORY_MISSING);
```

License
-------

[](#license)

The MIT License (MIT). Please see License File for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance93

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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 ~11 days

Total

7

Last Release

34d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5724738?v=4)[Lukman Nulhakim](/maintainers/LukmannulhakimAG)[@LukmannulhakimAG](https://github.com/LukmannulhakimAG)

---

Top Contributors

[![LukmannulhakimAG](https://avatars.githubusercontent.com/u/5724738?v=4)](https://github.com/LukmannulhakimAG "LukmannulhakimAG (26 commits)")

---

Tags

laravelcommonbase

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/common-my-laravel-common/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.4k](/packages/larastan-larastan)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9732.3M121](/packages/roots-acorn)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

76318.2M110](/packages/laravel-mcp)[propaganistas/laravel-disposable-email

Disposable email validator

6012.9M7](/packages/propaganistas-laravel-disposable-email)[api-platform/laravel

API Platform support for Laravel

59156.3k10](/packages/api-platform-laravel)

PHPackages © 2026

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