PHP code example of enea / laravel-sequenceable

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

    

enea / laravel-sequenceable example snippets


// simple sequence
Serie::lineal('document_number');

// sequence with scope
Serie::lineal('document_number')->scope('invoice');

// sequence with scope and fixed length
Serie::lineal('document_number')->scope('invoice')->length(8);

 namespace App;

use Enea\Sequenceable\Contracts\SequenceableContract;
use Enea\Sequenceable\Sequenceable;
use Enea\Sequenceable\Serie;
use Illuminate\Database\Eloquent\Model;

class Document extends Model implements SequenceableContract
{
    use Sequenceable;

    public function sequencesSetup(): array
    {
      return [
          Serie::lineal('document_number')
      ];
    }
}

    public function sequencesSetup(): array
    {
        return [ Serie::lineal('document_number') ];
    }

    public function sequencesSetup(): array
    {
        return [ 
            Serie::lineal('document_number')->scope($this->type())
        ];
    }

  	protected function type(): string
    {
        return $this->payment_document_type;
    }

    public function sequencesSetup(): array
    {
        return [ 
            Serie::lineal('document_number')->scope($this->type())->length(10)
        ];
    }

    public function sequencesSetup(): array
    {
        return [ 
            Wrap::create(PaymentSequence::class, 
                         fn(Wrap $wrap) => $wrap->column('document_number')->scope($this->type())->length(10))
        ];
    }

$collection = Succession::from(Document::class);

// return all sequences
$collection->all();

// find sequence by name
$collection->find('document_number', 'invoice');


return [    
    /*
    |--------------------------------------------------------------------------
    | Sequence Model
    |--------------------------------------------------------------------------
    |
    | This key defines the base sequence model that will be used to generate the autoincrementable 
    | values, you can modify this key and define your own sequence model whenever 
    | you implement the SequenceContract interface or extend the base model
    */
   'model' => \Enea\Sequenceable\Model\Sequence::class,
];

    public function sequencesSetup(): array
    {
        return [ 
             Wrap::create(CustomSequence::class, function(Wrap $wrap): void {
                $wrap->column('column-name');                
                $wrap->column('another-column-name');
                //..
            }),
        ];
    }
sh
php artisan vendor:publish --provider='Enea\Sequenceable\SequenceableServiceProvider'
sh
php artisan migrate