PHPackages                             protonemedia/laravel-mixins - 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. protonemedia/laravel-mixins

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

protonemedia/laravel-mixins
===========================

Laravel Mixins

3.9.0(4mo ago)15464.0k↓63.3%9[2 PRs](https://github.com/protonemedia/laravel-mixins/pulls)1MITPHPPHP ^8.2 || ^8.3 || ^8.4 || ^8.5CI passing

Since Sep 22Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/protonemedia/laravel-mixins)[ Packagist](https://packagist.org/packages/protonemedia/laravel-mixins)[ Docs](https://github.com/protonemedia/laravel-mixins)[ GitHub Sponsors](https://github.com/pascalbaljet)[ RSS](/packages/protonemedia-laravel-mixins/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (10)Dependencies (11)Versions (21)Used By (1)

Laravel Mixins
==============

[](#laravel-mixins)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f9f86f458abdd9fd4b8c4b6389e2001922be3d4294e97282b875d8a2cca6a47d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70726f746f6e656d656469612f6c61726176656c2d6d6978696e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/protonemedia/laravel-mixins)[![Total Downloads](https://camo.githubusercontent.com/a3a3cb5b449fe1a6531ad30e4d4a0c6a8c75a1f04ebd3d5187269abd6bce8179/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70726f746f6e656d656469612f6c61726176656c2d6d6978696e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/protonemedia/laravel-mixins)[![Buy us a tree](https://camo.githubusercontent.com/130148911f548b001b2ac68a32c0a06559977ca60ada3bf480c72ae4ea093175/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e)](https://plant.treeware.earth/protonemedia/laravel-mixins)

Sponsor Us
----------

[](#sponsor-us)

[![](https://camo.githubusercontent.com/b5348f68e9a1a6ff90432d75a6692be1d604b3320ce1fcabd4b1ef29668053c4/68747470733a2f2f696e657274696175692e636f6d2f76697369742d636172642e6a7067)](https://inertiaui.com/inertia-table?utm_source=github&utm_campaign=laravel-mixins)

❤️ We proudly support the community by developing Laravel packages and giving them away for free. If this package saves you time or if you're relying on it professionally, please consider [sponsoring the maintenance and development](https://github.com/sponsors/pascalbaljet) and check out our latest premium package: [Inertia Table](https://inertiaui.com/inertia-table?utm_source=github&utm_campaign=laravel-mixins). Keeping track of issues and pull requests takes time, but we're happy to help!

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

[](#requirements)

- PHP 8.2+
- Laravel 11.0

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

[](#installation)

You can install the package via composer:

```
composer require protonemedia/laravel-mixins
```

There's no Service Provider or automatic discovery/registration of anything. All features are opt-in.

Contents
--------

[](#contents)

#### Blade Directives

[](#blade-directives)

- [Decimal Money Formatter](#decimal-money-formatter)
- [Intl Money Formatter](#intl-money-formatter)

#### Console Commands

[](#console-commands)

- [Generate Sitemap](#generate-sitemap)

#### Validation Rules

[](#validation-rules)

- [Current password](#current-password)
- [Dimensions With Margin](#dimensions-with-margin)
- [Host](#host)
- [In Keys](#in-keys)
- [Max Words](#max-words)
- [URL Without Scheme](#url-without-scheme)

#### String Macros

[](#string-macros)

- [Compact](#compact)
- [Human Filesize](#human-filesize)
- [Text](#text)
- [URL](#url)
- [Seconds to time](#seconds-to-time)

#### PDF

[](#pdf)

- [PDF Regeneration](#pdf-regeneration)

#### Request

[](#request)

- [Convert Base64 input data to files](#convert-base64-input-data-to-files)

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

[](#blade-directives-1)

You can register Blade Directives by calling the `directive` method on the class. You can change the name of a directive with the optional first argument.

### Decimal Money Formatter

[](#decimal-money-formatter)

*Note: This directive requires the `moneyphp/money` package.*

Register the directive, for example by adding it to your `AppServiceProvider`:

```
ProtoneMedia\LaravelMixins\Blade\DecimalMoneyFormatter::directive();
```

You can customize the name of the directive and the default currency code:

```
ProtoneMedia\LaravelMixins\Blade\DecimalMoneyFormatter::directive('decimals', 'EUR');
```

The first argument of the directive is the amount in cents. The second optional parameter is the currency.

```
// 0.99
@decimals(99)

// 1.00
@decimals(100)

// 100
@decimals(100, 'XTS')
```

### Intl Money Formatter

[](#intl-money-formatter)

*Note: This directive requires the `moneyphp/money` package.*

Register the directive, for example by adding it to your `AppServiceProvider`:

```
ProtoneMedia\LaravelMixins\Blade\IntlMoneyFormatter::directive();
```

You can customize the name of the directive, the default currency code and the locale:

```
ProtoneMedia\LaravelMixins\Blade\IntlMoneyFormatter::directive('money', 'EUR', 'nl_NL');
```

The first argument of the directive is the amount in cents. The optional second parameter is the currency. The optional third parameter is the locale.

```
// € 0,99
@money(99)

// € 1,00
@money(100)

// US$ 1,00
@money(100, 'USD')

// 1 000,00 $US
@money(100, 'USD', 'fr')
```

Commands
--------

[](#commands)

### Generate Sitemap

[](#generate-sitemap)

*Note: This command requires the `spatie/laravel-sitemap` package.*

You can register the command by adding it to your `App\Console\Kernel` file, or by calling the `register` method on the class.

```
ProtoneMedia\LaravelMixins\Commands\GenerateSitemap::register();
```

You can also set a custom signature:

```
ProtoneMedia\LaravelMixins\Commands\GenerateSitemap::register('generate-sitemap');
```

It generates a sitemap of your entire site and stores it in the `public` folder as `sitemap.xml`.

```
php artisan sitemap:generate
```

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

[](#validation-rules-1)

### Current password

[](#current-password)

Passes if the value matches the password of the authenticated user.

```
$rule = new ProtoneMedia\LaravelMixins\Rules\CurrentPassword;
```

As of Laravel 9, this validation rule is [built-in](https://laravel.com/docs/11.x/validation#rule-current-password).

### Dimensions With Margin

[](#dimensions-with-margin)

Extension of the [Dimensions rule](https://laravel.com/docs/master/validation#rule-dimensions) with a `margin` option. Handy when you're working with ratios with repeating decimals.

```
use ProtoneMedia\LaravelMixins\Rules\DimensionsWithMargin;

$rule = DimensionsWithMargin::make()->ratio(20 / 9)->margin(1),
```

### Host

[](#host)

Verifies if the URL matches the given hosts.

```
use ProtoneMedia\LaravelMixins\Rules\Host;

$rule = Host::make(['facebook.com', 'fb.me']);
```

### In Keys

[](#in-keys)

Verifies if the given key or index exists in the array.

```
use ProtoneMedia\LaravelMixins\Rules\InKeys;

$rule = new InKeys(['laravel' => 'Laravel Framework', 'tailwindcss' => 'Tailwind CSS framework']);

// same as

use Illuminate\Validation\Rules\In;

$rule = new In(['laravel', 'tailwindcss']);
```

### Max Words

[](#max-words)

Passes if the value contains no more words than specified.

```
use ProtoneMedia\LaravelMixins\Rules\MaxWords;

$rule = MaxWords::make(250);
```

### URL Without Scheme

[](#url-without-scheme)

Passes if the URL is valid, even without a scheme.

```
$rule = new ProtoneMedia\LaravelMixins\Rules\UrlWithoutScheme;
```

String macros
-------------

[](#string-macros-1)

You can add new methods by using the mixins.

### Compact

[](#compact)

```
Str::mixin(new ProtoneMedia\LaravelMixins\String\Compact);

$string = "Hoe simpeler hoe beter. Want hoe minder keuze je een speler laat, hoe groter de kans dat hij het juiste doet.";

// Hoe simpeler hoe beter. Want hoe ... de kans dat hij het juiste doet.
echo Str::compact($string);
```

It has an optional second argument to specify the length on each side. With the optional third argument, you can specify the separator.

```
// Hoe simpeler hoe - het juiste doet.
echo Str::compact($string, 16, ' - ');
```

### Human Filesize

[](#human-filesize)

Converts a filesize into a human-readable version of the string.

```
Str::mixin(new ProtoneMedia\LaravelMixins\String\HumanFilesize);

$size = 3456789;

// '3.3 MB'
Str::humanFilesize($size));
```

### Text

[](#text)

*Note: This macro requires the `html2text/html2text` package.*

Converts HTML to plain text.

```
Str::mixin(new ProtoneMedia\LaravelMixins\String\Text);

$html = "Protone Media";

// Protone Media
Str::text($html);
```

### URL

[](#url)

Prepends `https://` if the scheme is missing from the given URL.

```
Str::mixin(new ProtoneMedia\LaravelMixins\String\Url);

$url = "protone.media";

// https://protone.media
Str::url($url);
```

### Seconds to time

[](#seconds-to-time)

Converts seconds to a 'mm:ss' / 'hh:mm:ss' format.

```
Str::mixin(new ProtoneMedia\LaravelMixins\String\SecondsToTime);

Str::secondsToTime(10); // 00:10
Str::secondsToTime(580); // 09:40
Str::secondsToTime(3610); // 01:00:10

// force 'hh:mm:ss' format, even under an hour:
Str::secondsToTime(580, false); // 00:09:40
```

PDF Regeneration
----------------

[](#pdf-regeneration)

*Note: Requires the `symfony/process` package.*

Regenerates the PDF content with Ghostscript.

```
$ghostscript = new ProtoneMedia\LaravelMixins\Pdf\Ghostscript;

$regeneratedPdf = $ghostscript->regeneratePdf(
    file_get_contents('/uploads/invoice.pdf')
);
```

You can specify the path of the `ghostscript` binary as well:

```
$ghostscript = new Ghostscript('gs-binary');
```

Convert Base64 input data to files
----------------------------------

[](#convert-base64-input-data-to-files)

Add the `ConvertsBase64ToFiles` trait and `base64FileKeys` method to your form request.

```
use Illuminate\Foundation\Http\FormRequest;
use ProtoneMedia\LaravelMixins\Request\ConvertsBase64ToFiles;

class ImageRequest extends FormRequest
{
    use ConvertsBase64ToFiles;

    protected function base64FileKeys(): array
    {
        return [
            'jpg_image' => 'Logo.jpg',
        ];
    }

    public function rules()
    {
        return [
            'jpg_image' => ['required', 'file', 'image'],
        ];
    }
}
```

Now you can get the files like regular uploaded files:

```
$jpgFile = $request->file('jpg_image');

// Logo.jpg
$jpgFile->getClientOriginalName();
```

This trait supports nested data as well. You can either reference the keys by a nested array, or with a [dotted notation](https://laravel.com/docs/master/helpers#method-array-dot):

```
class ImageRequest extends FormRequest
{
    use ConvertsBase64ToFiles;

    protected function base64FileKeys(): array
    {
        return [
            'company.logo' => 'Logo.jpg',
            'user' => [
                'avatar' => 'Avatar.jpg',
            ],
        ];
    }
}
```

Want to know more about this trait? Check out the [blog post](https://protone.media/blog/convert-and-store-base64-encoded-files-in-laravel-use-validation-rules-and-access-the-decoded-files-from-the-request-instance).

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Other Laravel packages
----------------------

[](#other-laravel-packages)

- [Inertia Modal](https://inertiaui.com/inertia-modal/docs/introduction): With Inertia Modal, you can easily open any route in a Modal or Slideover without having to change anything about your existing routes or controllers.

- [`Inertia Table`](https://inertiaui.com/inertia-table?utm_source=github&utm_campaign=laravel-mixins): The Ultimate Table for Inertia.js with built-in Query Builder.
- [`Laravel Blade On Demand`](https://github.com/protonemedia/laravel-blade-on-demand): Laravel package to compile Blade templates in memory.
- [`Laravel Cross Eloquent Search`](https://github.com/protonemedia/laravel-cross-eloquent-search): Laravel package to search through multiple Eloquent models.
- [`Laravel Eloquent Scope as Select`](https://github.com/protonemedia/laravel-eloquent-scope-as-select): Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.
- [`Laravel FFMpeg`](https://github.com/protonemedia/laravel-ffmpeg): This package provides an integration with FFmpeg for Laravel. The storage of the files is handled by Laravel's Filesystem.
- [`Laravel MinIO Testing Tools`](https://github.com/protonemedia/laravel-minio-testing-tools): Run your tests against a MinIO S3 server.
- [`Laravel Paddle`](https://github.com/protonemedia/laravel-paddle): Paddle.com API integration for Laravel with support for webhooks/events.
- [`Laravel Task Runner`](https://github.com/protonemedia/laravel-task-runner): Write Shell scripts like Blade Components and run them locally or on a remote server.
- [`Laravel Verify New Email`](https://github.com/protonemedia/laravel-verify-new-email): This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.
- [`Laravel XSS Protection`](https://github.com/protonemedia/laravel-xss-protection): Laravel Middleware to protect your app against Cross-site scripting (XSS). It sanitizes request input, and it can sanatize Blade echo statements.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Pascal Baljet](https://github.com/protonemedia)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Treeware
--------

[](#treeware)

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/protonemedia/laravel-mixins) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

###  Health Score

60

—

FairBetter than 98% of packages

Maintenance76

Regular maintenance activity

Popularity46

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 89.2% 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 ~141 days

Recently: every ~273 days

Total

15

Last Release

138d ago

Major Versions

1.0.0 → 2.0.02020-10-05

2.1.0 → 3.0.02020-11-27

PHP version history (8 changes)1.0.0PHP ^7.4

3.0.0PHP ^7.4 || ^8.0

3.1.0PHP ^7.4 || ^8.0 || ^8.1

3.4.0PHP ^8.0 || ^8.1 || ^8.2

3.5.0PHP ^8.1 || ^8.2

3.6.0PHP ^8.1 || ^8.2 || ^8.3

3.8.0PHP ^8.2 || ^8.3 || ^8.4

3.9.0PHP ^8.2 || ^8.3 || ^8.4 || ^8.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8403149?v=4)[Pascal Baljet](/maintainers/pascalbaljet)[@pascalbaljet](https://github.com/pascalbaljet)

---

Top Contributors

[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (66 commits)")[![realpascalbotjet](https://avatars.githubusercontent.com/u/262015488?v=4)](https://github.com/realpascalbotjet "realpascalbotjet (4 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![hofmannsven](https://avatars.githubusercontent.com/u/1214387?v=4)](https://github.com/hofmannsven "hofmannsven (1 commits)")

---

Tags

laravelphpprotonemedialaravel-mixins

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/protonemedia-laravel-mixins/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M10](/packages/renatomarinho-laravel-page-speed)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/redis

The Illuminate Redis package.

8314.6M377](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

244.6M138](/packages/illuminate-cookie)

PHPackages © 2026

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