PHP code example of irfa / php-sn-generator

1. Go to this page and download the library: Download irfa/php-sn-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

irfa / php-sn-generator example snippets


'providers' => [
            ....
            Irfa\SerialNumber\SerialNumberGeneratorSeviceProvider::class,
     ];

'aliases' => [
         ....
  		'SN' => Irfa\SerialNumber\Facades\SerialNumber::class,

    ],

 
	return [ 
	/*
    |--------------------------------------------------------------------------
    | Serial Config
    |--------------------------------------------------------------------------
    |
    | length    : length for one segment
    | segment   : segment amount for Serial number 
    | seperator : striped segment for serial (set null if you do not wish to use seperator)
    |
    */
		'length'	=> 4,

		'segment'	=> 4,
	
	    	'seperator'     => "-",
	
	    	'charset'       => "0123456789ABCDEFGHIJKLMNPQRSTUWXYZ",

];



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use SN;

class SomethingController extends Controller
{
   
    public function generate_serial(Request $request)
    {
        return SN::generate(); //result : TP8K-XU63-9YN3-SMSF
    }
}


a\SerialNumber\Func\SerialNumber;

$sn = new SerialNumber();

echo $sn->generate(); //result : TP8K-XU63-9YN3-SMSF
   

//Laravel
SN::setConfig([	
		'length' => 5,
		'segment' => 4,
		'seperator' => '-',
		'charset' => "123456789ABCDEFGH"])
	->generate();
	
//PHP Native
$sn = new SerialNumber();

echo $sn->setConfig([	
                        'length' => 5,
                        'segment' => 4,
                        'seperator' => '-',
                        'charset' => "123456789ABCDEFGH"
                    ])
		->generate();
bash
php artisan vendor:publish --tag=php-serial-number
bash
config/irfa/serial_number.php
bash
vendor/irfa/php-sn-generator/config/config.php