finagin / laravel-extra-support
Extra Support methods for Laravel
0.1.0
2021-07-15 16:25 UTC
Requires
- php: ^7.2.5|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/php-code-coverage: *
This package is auto-updated.
Last update: 2024-12-15 23:57:59 UTC
README
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.