PHP code example of alfa6661 / laravel-autonumber

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

    

alfa6661 / laravel-autonumber example snippets


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

use Alfa6661\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' => 'SO.?', // 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 'SO/' . 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. X',
]);

echo $order->order_number;

// SO/20170803/00001

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

php artisan migrate