PHPackages                             pepperfm/macros-for-laravel - 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. pepperfm/macros-for-laravel

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

pepperfm/macros-for-laravel
===========================

A small macro registry for Laravel facades / macroable classes.

1.0.0(1mo ago)01.2k↓56.2%MITPHPPHP ^8.4

Since Jan 19Pushed 1mo agoCompare

[ Source](https://github.com/pepperfm/macros-for-laravel)[ Packagist](https://packagist.org/packages/pepperfm/macros-for-laravel)[ RSS](/packages/pepperfm-macros-for-laravel/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (31)Versions (8)Used By (0)

Laravel Macros
==============

[](#laravel-macros)

Small macro registry for Laravel facades and Macroable classes. It lets you enable macro groups via config and register everything automatically at boot.

Install
-------

[](#install)

```
composer r pepperfm/macros-for-laravel
```

Laravel auto-discovers the provider: `Pepperfm\LaravelMacros\Providers\LaravelMacrosServiceProvider`.

Publish config
--------------

[](#publish-config)

```
php artisan vendor:publish --tag=macros-for-laravel-config
```

`config/macros-for-laravel.php`:

```
return [
    'enabled' => env('MACROS_ENABLED', true),
    'profile' => env('MACROS_PROFILE', 'default'),
    'conflicts' => 'throw', // throw | overwrite
    'unreachable' => 'throw', // throw | skip
    'profiles' => [
        'default' => [
            \Pepperfm\LaravelMacros\Groups\Support\ArrCastMacros::class => true,
            \Pepperfm\LaravelMacros\Groups\Support\ArrNativeMacros::class => true,
            \Pepperfm\LaravelMacros\Groups\Cache\CacheCastMacros::class => true,
            \Pepperfm\LaravelMacros\Groups\Config\ConfigCastMacros::class => true,
            \Pepperfm\LaravelMacros\Groups\Support\CollectionMacros::class => true,
        ],
        // 'http' => [
        //     \Pepperfm\LaravelMacros\Groups\Facades\ResponseMacros::class => true,
        // ],
    ],
];
```

Switch profiles via env:

```
MACROS_PROFILE=http
```

You can also use the legacy top-level groups list (no profiles):

```
'groups' => [
    \Pepperfm\LaravelMacros\Groups\Support\ArrCastMacros::class => true,
];
```

Built-in macros
---------------

[](#built-in-macros)

### Arr cast helpers

[](#arr-cast-helpers)

Available when `ArrCastMacros` is enabled:

```
Arr::toBool($array, 'flag');
Arr::toInt($array, 'count');
Arr::toFloat($array, 'ratio');
Arr::toString($array, 'name', null, true);
Arr::toArray($array, 'items');
Arr::toEnum($array, 'status', Status::class, $default = null);
```

### Arr native array helpers

[](#arr-native-array-helpers)

Available when `ArrNativeMacros` is enabled:

```
Arr::values($array);
Arr::keys($array);
Arr::keyFirst($array);
Arr::keyLast($array);
Arr::flip($array);
Arr::combine(['a', 'b'], [1, 2]);
Arr::unique(['a', 'a', 'b']);
Arr::reverse([1, 2, 3]);
```

### Collection paginate

[](#collection-paginate)

Available when `CollectionMacros` is enabled:

```
collect([1, 2, 3])->paginate(2);
```

### Collection filters

[](#collection-filters)

Available when `CollectionMacros` is enabled:

```
collect([1, null, 2])->filterNotNull();
collect(['', ' ', 'ok', null])->filterNotBlank();
```

### Cache typed getters

[](#cache-typed-getters)

Available when `CacheCastMacros` is enabled:

```
cache()->toBool('enabled', false);
cache()->toInt('count', 0);
cache()->toFloat('ratio', 0.0);
cache()->toString('name', 'guest', true);
cache()->toArray('filters', []);
cache()->toEnum('status', Status::class, Status::Draft);

Cache::toString('name', 'guest');
cache()->store('redis')->toInt('count', 0);
```

`cache('name', 'guest')->toString()` is not supported because Laravel's `cache()`helper returns the raw cached value when a key is passed.

### Config typed getters

[](#config-typed-getters)

Available when `ConfigCastMacros` is enabled:

```
config()->toBool('features.enabled', false);
config()->toInt('features.count', 0);
config()->toFloat('features.ratio', 0.0);
config()->toString('app.name', 'Laravel', true);
config()->toArray('features.filters', []);
config()->toEnum('features.status', Status::class, Status::Draft);

Config::toString('app.name', 'Laravel');
```

`config('app.name', 'Laravel')->toString()` is not supported because Laravel's `config()` helper returns the raw config value when a key is passed.

Custom groups
-------------

[](#custom-groups)

Create a group that implements `Pepperfm\LaravelMacros\Contracts\MacroGroupContract`, then add it to a profile (or to `groups` in legacy mode). It will be resolved via the container.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance91

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

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

Recently: every ~41 days

Total

7

Last Release

44d ago

Major Versions

0.1.0 → 1.0.02026-07-06

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/36007880?v=4)[Dmitry](/maintainers/PepperFM)[@pepperfm](https://github.com/pepperfm)

---

Top Contributors

[![pepperfm](https://avatars.githubusercontent.com/u/36007880?v=4)](https://github.com/pepperfm "pepperfm (9 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/pepperfm-macros-for-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/pepperfm-macros-for-laravel/health.svg)](https://phpackages.com/packages/pepperfm-macros-for-laravel)
```

###  Alternatives

[propaganistas/laravel-disposable-email

Disposable email validator

6023.2M7](/packages/propaganistas-laravel-disposable-email)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k2](/packages/mike-bronner-laravel-model-caching)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9922.4M146](/packages/roots-acorn)[aedart/athenaeum

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

265.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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