All Projects β†’ alfa6661 β†’ laravel-autonumber

alfa6661 / laravel-autonumber

Licence: other
Laravel package to create autonumber for Eloquent model

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-autonumber

Eloquent Approval
Approval process for Laravel Eloquent models
Stars: ✭ 79 (+203.85%)
Mutual labels:  eloquent, eloquent-models
Laravel Deletable
πŸ‘Ύ Gracefully restrict deletion of Laravel Eloquent models
Stars: ✭ 137 (+426.92%)
Mutual labels:  eloquent, eloquent-models
Laravel Nullable Fields
Handles saving empty fields as null for Eloquent models
Stars: ✭ 88 (+238.46%)
Mutual labels:  eloquent, eloquent-models
Elasticquent
Maps Laravel Eloquent models to Elasticsearch types
Stars: ✭ 1,172 (+4407.69%)
Mutual labels:  eloquent, eloquent-models
laravel-nestedupdater
Package for allowing updating of nested Eloquent model relations using a single nested data array.
Stars: ✭ 19 (-26.92%)
Mutual labels:  eloquent, eloquent-models
Laravel Lucene Search
Laravel 4.2, 5.* package for full-text search over Eloquent models based on ZF2 Lucene.
Stars: ✭ 75 (+188.46%)
Mutual labels:  eloquent, eloquent-models
Searchable
Search/filter functionality for Laravel's Eloquent models
Stars: ✭ 113 (+334.62%)
Mutual labels:  eloquent, eloquent-models
Eloquent Relativity
Allows you to decouple your eloquent models from one another.
Stars: ✭ 112 (+330.77%)
Mutual labels:  eloquent, eloquent-models
eloquence
Eloquence provides a cache on top of Eloquent that prevents multiple models being created for a single database row using the Identity Map design pattern.
Stars: ✭ 18 (-30.77%)
Mutual labels:  eloquent, eloquent-models
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (+815.38%)
Mutual labels:  eloquent, eloquent-models
Eloquentfilter
An Eloquent Way To Filter Laravel Models And Their Relationships
Stars: ✭ 1,113 (+4180.77%)
Mutual labels:  eloquent, eloquent-models
inertiajs-tables-laravel-query-builder
Inertia.js Tables for Laravel Query Builder
Stars: ✭ 391 (+1403.85%)
Mutual labels:  eloquent, eloquent-models
Laravel Transactional Model Events
Add eloquent model events fired after a transaction is committed or rolled back
Stars: ✭ 52 (+100%)
Mutual labels:  eloquent, eloquent-models
Laravel Schedulable
Schedule and unschedule eloquent models elegantly without cron jobs
Stars: ✭ 78 (+200%)
Mutual labels:  eloquent, eloquent-models
Laravel Cascade Soft Deletes
Cascading deletes for Eloquent models that implement soft deletes
Stars: ✭ 498 (+1815.38%)
Mutual labels:  eloquent, eloquent-models
Eloquent Hashids
On-the-fly hashids for Laravel Eloquent models. (🍰 Easy & ⚑ Fast)
Stars: ✭ 196 (+653.85%)
Mutual labels:  eloquent, eloquent-models
laravel-quasar
β°πŸ“Šβœ¨Laravel Time Series - Provides an API to create and maintain data projections (statistics, aggregates, etc.) from your Eloquent models, and convert them to time series.
Stars: ✭ 78 (+200%)
Mutual labels:  eloquent, eloquent-models
encryptable
Laravel package for persisting encrypted Model properties, providing decryption when accessed.
Stars: ✭ 26 (+0%)
Mutual labels:  eloquent, eloquent-models
laravel-repository
Repository pattern implementation for Laravel
Stars: ✭ 49 (+88.46%)
Mutual labels:  eloquent
laravel-geoly
Perform fast and efficient radius searches on your Laravel Eloquent models.
Stars: ✭ 25 (-3.85%)
Mutual labels:  eloquent

Laravel AutoNumber

Latest Stable Version Total Downloads StyleCI License

Laravel package to create autonumber for Eloquent model

Installation

You can install the package via composer:

composer require alfa6661/laravel-autonumber

Register the ServiceProvider in config/app.php

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

Publish the default configuration

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

Running migration

php artisan migrate

Usage

Your Eloquent models should use the Alfa6661\AutoNumber\AutoNumberTrait trait

The trait contains an abstract method getAutoNumberOptions() that you must implement yourself.

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
            ]
        ];
    }

}

You can also pass a closure for the format value.

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
        ]
    ];
}

Saving Model

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

The order_number will be automatically generated based on the format given when saving the Order model.

echo $order->order_number;

// SO/20170803/00001

License

Laravel-autonumber is open-sourced software licensed under the MIT license.

Contributing

Please report any issue you find in the issues page. Pull requests are more than welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].