PHP code example of virusphp / autonumbering

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

    

virusphp / autonumbering example snippets


'providers' => [
    // ...
	Virusphp\AutoNumber\AutoNumberServiceProvider::class,
],

use Virusphp\AutoNumber\AutoNumberTrait;

class Order extends Model
{
    use AutoNumberTrait;

    /**
     * Return the autonumber configuration array for this model.
     *
     * @return array
     */
    public function getAutoNumberOptions()
    {
        return [
            'order_number' => [
                'format' => 'PO.?', // autonumber format. '?' will be replaced with the generated number.
                'length' => 5 // The number of digits in an autonumber
            ]
        ];
    }

}

public function getAutoNumberOptions()
{
    return [
        'order_number' => [
            'format' => function () {
                return 'PO/' . date('Ymd') . '/?'; // autonumber format. '?' will be replaced with the generated number.
            },
            'length' => 5 // The number of digits in the autonumber
        ]
    ];
}

$order = Order::create([
    'customer' => 'Mr. PO',
]);

echo $order->order_number;

// PO/20170803/00001

php artisan vendor:publish --provider='Virusphp\AutoNumber\AutoNumberServiceProvider'

php artisan migrate