Looking to hire Laravel developers? Try LaraJobs

laravel-extra-support maintained by finagin

Description
Extra Support methods for Laravel
Author
Last update
2021/07/15 18:25 (dev-develop)
License
Downloads
4

Comments
comments powered by Disqus

Laravel Extra Support

StyleCI GitHub Actions GitHub Issues Total Downloads Latest Stable Version Software License

Installation

composer require finagin/laravel-extra-support

Usage

Str::randomWithExclude()

Returns random string with excludes.

use Illuminate\Support\Str;

Str::randomWithExclude();
Str::randomWithExclude(15);
Str::randomWithExclude(16, ['a', 'b', 'c']);
Str::randomWithExclude(16, 'abc');

Str::randomAlpha()

Returns random string without numeric.

use Illuminate\Support\Str;

Str::randomAlpha();
Str::randomAlpha(15);

Customization

<?php

namespace App\Services;

use Finagin\ExtraSupport\Services\MacrosRegistrar;
use Illuminate\Support\Str;

class CustomMacrosRegistrar extends MacrosRegistrar
{
    /**
     * @return \Illuminate\Support\Collection|array
     */
    public function additionalRegisters()
    {
        return [
            '\\Illuminate\\Support\\Str@randomExcludeSimilar' => 'registerMacroRandomExcludeSimilar',
        ];
    }

    protected function registerMacroRandomExcludeSimilar()
    {
        Str::macro('randomExcludeSimilar', static function ($length = 16) {
            return Str::randomWithExclude($length, ['1', 'l', '0', 'O']);
        });
    }
}

In config replace registrar with new registrar class:

<?php

return [

    'registrar' => \App\Services\CustomMacrosRegistrar::class,
    
    // ...
];

Finally, add dependencies to the appropriate section if you need them:

<?php

return [
    // ...
    'dependencies' => [
        // ...
        '\\Illuminate\\Support\\Str@randomExcludeSimilar' => [
            '\\Illuminate\\Support\\Str@randomWithExclude',
        ],
        // ...
    ],
    // ...
];

License

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