PHP code example of mdcoderu / sequential-code

1. Go to this page and download the library: Download mdcoderu/sequential-code 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/ */

    

mdcoderu / sequential-code example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mdcode\SequentialCode\Traits\HasSequentialCode;

use Mdcoderu\SequentialCode\Traits\HasSequentialCode;

class Order extends Model
{
    use HasSequentialCode;
    
    // ...
}

$order = Order::create([
    // другие поля...
]);

echo $order->code; // "100000", "100001", ...

$order = Order::create([
    'code' => 123456,
    // другие поля...
]);

class Order extends Model
{
    use HasSequentialCode;
  
    protected function getSequentialCodeKey(): string
    {
        return 'order_' . $this->type;
    }
}

return [
    'min_code' => 100000, // Минимальное значение кода
    'max_code' => 999999, // Максимальное значение кода
];
bash
php artisan vendor:publish --tag="sequential-code-migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --tag="sequential-code-config"