PHP code example of guava / laravel-sequence

1. Go to this page and download the library: Download guava/laravel-sequence 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/ */

    

guava / laravel-sequence example snippets


use Carbon\Carbon;
use Guava\Sequence\Enums\ResetFrequency;
use Guava\Sequence\Models\SequenceRule;
use Guava\Sequence\SequenceFactory;

/**
 * Create new sequence rule. It needs to be done only once.
 */
SequenceRule::create([
    'type'            => 'invoice',
    'pattern'         => '{number}/COMPANY/{year}',
    'reset_frequency' => ResetFrequency::YEARLY,
]);

/**
 * Make sequence factory via container or DI.
 */
$factory = app(SequenceFactory::class);

/**
 * Create sequence by passing sequence type and date (e.g. issue date of invoice).
 */
$sequence = $factory->create(
    'invoice',
    Carbon::createFromFormat('Y-m-d', '2021-06-01')
);

/**
 * Public methods of sequence.
 */
$ordinal = $sequence->getOrdinalNumber(); // e.g. 21
$number  = $sequence->getNumber();        // e.g. 21/COMPANY/2021
$pattern = $sequence->getPattern();       // e.g. {number}/COMPANY/{year}

/**
 * After use of generated number, manual increment of ordinal number is