Code Monkey home page Code Monkey logo

laravel-id-generator's Introduction

laravel-id-generator's People

Contributors

haruncpi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-id-generator's Issues

Using library with Postresql

I have tried using your library with Postgresql but it throws this error:

ERROR: syntax error at or near "describe"
LINE 1: describe deliveries
^
SQL state: 42601
Character: 1

It seams to me that $colsType = DB::select('describe ' . $table); is the issue because describe is not supported by Postgresql.
Could you provide a workaround for this?

ErrorException : A non-numeric value encountered

ErrorException : A non-numeric value encountered

at C:\xampp\htdocs\myshop\vendor\haruncpi\laravel-id-generator\src\IdGenerator.php:50
46| if ($total[0]->total) {
47| $maxQuery = sprintf("SELECT MAX(SUBSTR(%s,%s,%s)) maxId FROM %s %s",
48| $field, ($prefixLength + 1), $idLength, $configArr['table'], $whereString);
49| $maxId = DB::select($maxQuery);

50| $maxId = $maxId[0]->maxId + 1;
51|
52| return $configArr['prefix'] . str_pad($maxId, $idLength, '0', STR_PAD_LEFT);
53| } else {
54| return $configArr['prefix'] . str_pad(1, $idLength, '0', STR_PAD_LEFT);

Exception trace:

1 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("A non-numeric value encountered", "C:\xampp\htdocs\myshop\vendor\haruncpi\laravel-id-generator\src\IdGenerator.php")
C:\xampp\htdocs\myshop\vendor\haruncpi\laravel-id-generator\src\IdGenerator.php:50

2 Haruncpi\LaravelIdGenerator\IdGenerator::generate(["users", "INV"])
C:\xampp\htdocs\myshop\app\User.php:56

User boot function:
public static function boot() { parent::boot(); static::creating(function ($user) { $user->pin = IdGenerator::generate(['table' => 'users', 'length' => 10, 'prefix' =>'INV']); }); }

Auto generated id not increamenting

i use the package in my admin panel, Id generated very nice but it don't increamenting.
it's as 2104020001, 2104020001
I want as 2104020001, 0002, 0003
so please help me as soon as possible.

Undefined array key 0

I am having an error of:

ErrorException
Undefined array key 0

and the code is:
public static function boot()
{
parent::boot();
self::creating(function (Product $model) {
$model->barcodeID = IdGenerator::generate(['table'=>'products','length'=> 4,'prefix'=>date('y')]);
});
}

any ideas?

Undefined property: stdClass::$column_name

all of a sudden i started getting the error

 Undefined property: stdClass::$column_name

  at vendor/haruncpi/laravel-id-generator/src/IdGenerator.php:28
     24▕         $fieldType = null;
     25▕         $fieldLength = null;
     26▕ 
     27▕         foreach ($rows as $col) {
  ➜  28▕             if ($field == $col->column_name) {
     29▕                 $fieldType = $col->data_type;
     30▕                 if ($driver == 'mysql') {
     31▕                     //example: column_type int(11) to 11
     32▕                     preg_match("/(?<=\().+?(?=\))/", $col->column_type, $tblFieldLength);

any idea what could be the reason ?

Exactly where do you paste the code

You're missing documentation on exactly what files to generate or where to paste the code in a laravel application. Migrations? if so where?
Great idea, just missing details for deployment

Update and enhance the package.

Hello @haruncpi ,

As the last release of the package is more than 2 years old, I'd like to submit a PR to update and enhance this package as well as optimising its source code.

If you are free and available to review the PR I'm submitting, please tell so I can proceed.

Request - Foereing key as parameter

Hello,
It should be great if you could add a foreign key in the parameter to start a new invoice number.
For example i have invoices related to offices. My need is to seperate invoices numbers per offices, so if i could put the office id in parameters it would be useful.
Thanks for your great work.

Count also other prefixes in the table!

Love the package!

The package does count in the records that uses other prefixes in the same table, so that when you want to start with a new prefix it should start with 001.

Make it required to count only the records with the given prefix.

Happy to submit a PR.

Undefined array key 0

$task = Task::create([
'task_id' => IdGenerator::generate(['table' => 'tasks', 'length' => 6, 'prefix' => 'TSK-']),
)

I have tried using Idgenerator, but i am getting this error Undefined array key 0

Adaptive lenght?

Is there a way to use it with adaptive length? say I want it to start as: OP-1 and keep going on and on ?

example:
starts as OP-1
at 154 records its OP-154
at 23123123 records its: OP-23123123

Thanks!

String comparison problem

good package and i'd like to contribute to make it better.

MySQL MAX only is not the safest way to get the maximum value of a column bcz it uses string comparison which means 20P999 is greater than 20P1000 (bcz the first 9 is greater than the first 1 on the second ID) overall which is not true.

you can argue why i didn't put in the the appropriate length before starting creating the ids but sometimes you dont know how far the number is going to get and you dont want to have a lot of unessesary zeros in an id.

they way around it i'm using right now is this

SELECT MAX(CAST((SUBSTRING(%s,($prefixLength + 1), $idLength)) AS UNSIGNED)) maxId from %s;

A non-numeric value encountered

Success on saving the first data but an error appears when saving the next data

$id = IdGenerator::generate(['table' => 'data', 'length' => 10, 'prefix' =>$user->idn.'-']);

🧨_A_non-numeric_value_encountered

table field type is int but prefix is string

Hi @haruncpi! I hope you're doing well.
your package is awesome.

I just have an issue with inserting a value with a type string in the prefix key.

I tried the same example in the docs as bellow:
$id = IdGenerator::generate(['table' => 'invoices', 'length' => 10, 'prefix' =>'INV-']);

And I'm getting this error: "table field type is int but prefix is string"

Thanks

Add a new key for the initial value

I think it will be useful if you add a new key in the associative array that passes into the generate function to set the initial value for the id after the prefix because in some cases I don't want to start from 1.

Example: I want to start the id from T10001

what happens when the length is exceeded ?

for example lets say u have a length of 3 so the generated id is 001 of max 999,
so what happens when the table records exceeds that length ex.1000 ?

does the pkg reset the id ?
does it increase the length ?
does it throw an exception ? & if so can we increase it automatically ?

getting error on Laravel 9

I am getting following error on Laravel 9

SQLSTATE[HY000]: General error: 1 no such table: information_schema.columns (SQL: SELECT column_name AS "column_name",data_type AS "data_type" FROM information_schema.columns WHERE table_catalog=:database AND table_name=:table)

Success to generate in Database but showing 0 in view table

Hi There,

can someone help me out, I successfully generated the id to my database but in the view file it shows 0

Model:

public static function boot() { parent::boot(); self::creating(function ($id) { $config=[ 'table'=>'orders', 'field'=>'awb', 'length'=>10, 'prefix'=>'TEX-' ]; $id->awb = IdGenerator::generate($config); }); }

Database:

Screenshot 2021-08-15 210509

View:
Screenshot 2021-08-15 210620

table field type is int but prefix is string

Hi @haruncpi! I hope you're doing well.
your package is awesome.

I just have an issue with inserting a value with a type string in the prefix key.

I tried the same example in the docs as bellow:
$id = IdGenerator::generate(['table' => 'invoices', 'length' => 10, 'prefix' =>'INV-']);

And I'm getting this error: "table field type is int but prefix is string"

As a temporary solution, I just commented this code in IdGenerator.php

if (in_array($tableFieldType, ['int', 'bigint', 'numeric']) && !is_numeric($prefix)) { throw new Exception("table field type is $tableFieldType but prefix is string"); }

I hope you fix this issue soon.

Thanks.

How To Generate New ID Without Reloading The Page?

Hi!, i'm really grateful for using this package because it makes my work so much easier, Thank you so much.

So, i'm using Ajax JQuery for my current project with this package. As we know when we use Ajax for HTTP handling we don't need to reload the page. Is it possible to generate new ID without getting any reload in our page? Because as i know the custom ID will be re-generate automatically after the page reloaded.

Thank you so much for any kind of help

Using $this when not in object context

This is my code in the model:

 public static function boot(){
        parent::boot();
        self::creating(function ($model) {
            $model->uuid = IdGenerator::generate(['table' => $this->table, 'length' => 10, 'prefix' =>'#AST-']);
        });
    }

I can't add a new record because everytime i try, i get this error.

Problem with different prefix and same table:

I i want to generate an id with this data:

array:5 [▼
"table" => "estimates"
"length" => 8
"field" => "number"
"prefix" => "E-"
"reset_on_prefix_change" => false
]

If my table contains:

E-000001
IND-000001

next code is: "E-000001"

Why?

Error on creating record

I'm getting an error upon creating a new record

here is the errror

message": "SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near \"describe\"\nLINE 1: describe orders\n        ^ (SQL: describe orders)",
    "exception": "Illuminate\\Database\\QueryException",

here is how I'm using the plugin

public static function boot()
    {
        parent::boot();

        self::creating(function ($model)
        {
            $model->order_num = IdGenerator::generate(['table' => 'orders', 'length' => 9, 'prefix' => '#']);
        });
    }

how may I fix this ? thanks in advance

Undefined offset: 0

laravel 8.28.1
haruncpi/laravel-id-generator 1.0.5

Undefined offset: 0 error when the field datatype is "int".

id field type is bigint but prefix is string

$code_generate = 'LYB';
$insert = DB::table('orders')->insertGetId([
            'user_id' => Auth::user()->id,
            'order_code' => IdGenerator::generate(['table' => 'orders', 'length' => 9, 'prefix' => $code_generate]),
            'payment_type' => (int)$request->payment_type,
            'address_id' => (int)$address->id,
            'no_of_product' => count($order_list),
            'subtotal' => $subtotal,
            'shipping' => $shipping,
            'total' => $total,
        ]);

image

Error 'a non-numeric value encountered' when generate id

this my code :

$validatedData = $request->validated();
$validatedData['kode'] = IdGenerator::generate(['table' => 'kandang', 'length' => 2, 'prefix' => 'KD-']);
$kandang = Kandang::create($validatedData);
return $kandang;

image
I was suspicious of the code on line 50, because after I checked it, the $maxId[0] turned out to be null.

error trace :
"message": "A non-numeric value encountered",
"exception": "ErrorException",
"file": "D:\Projects\peternakan\api\vendor\haruncpi\laravel-id-generator\src\IdGenerator.php",
"line": 50,
"trace": [
{
"file": "D:\Projects\peternakan\api\vendor\haruncpi\laravel-id-generator\src\IdGenerator.php",
"line": 50,
"function": "handleError",
"class": "Illuminate\Foundation\Bootstrap\HandleExceptions",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\app\Http\Controllers\KandangController.php",
"line": 15,
"function": "generate",
"class": "Haruncpi\LaravelIdGenerator\IdGenerator",
"type": "::"
},
{
"function": "store",
"class": "App\Http\Controllers\KandangController",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Controller.php",
"line": 54,
"function": "call_user_func_array"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php",
"line": 45,
"function": "callAction",
"class": "Illuminate\Routing\Controller",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Route.php",
"line": 219,
"function": "dispatch",
"class": "Illuminate\Routing\ControllerDispatcher",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Route.php",
"line": 176,
"function": "runController",
"class": "Illuminate\Routing\Route",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 681,
"function": "run",
"class": "Illuminate\Routing\Route",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 130,
"function": "Illuminate\Routing\{closure}",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\spatie\laravel-permission\src\Middlewares\RoleMiddleware.php",
"line": 25,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 171,
"function": "handle",
"class": "Spatie\Permission\Middlewares\RoleMiddleware",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php",
"line": 41,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Routing\Middleware\SubstituteBindings",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php",
"line": 59,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Routing\Middleware\ThrottleRequests",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 105,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 683,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 658,
"function": "runRouteWithinStack",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 624,
"function": "runRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 613,
"function": "dispatchToRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
"line": 170,
"function": "dispatch",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 130,
"function": "Illuminate\Foundation\Http\{closure}",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php",
"line": 21,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php",
"line": 21,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php",
"line": 27,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\ValidatePostSize",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php",
"line": 62,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\fideloper\proxy\src\TrustProxies.php",
"line": 57,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 171,
"function": "handle",
"class": "Fideloper\Proxy\TrustProxies",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 105,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
"line": 145,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
"line": 110,
"function": "sendRequestThroughRouter",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\public\index.php",
"line": 55,
"function": "handle",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "D:\Projects\peternakan\api\server.php",
"line": 21,
"function": "require_once"
}
]

IdGenerator doest generate unique IDs

Hello,

Using this package in my project like this in an orders model:

 public static function boot()
    {
        parent::boot();
        self::creating(function ($model) {
            $model->order_number = IdGenerator::generate(['table' => 'orders', 'length' => 6, 'prefix' => date('y')]);
        });
    }

But it doesnt generate unique ids:

https://i.imgur.com/FvRKnlj.png

Any idea why?

A non-numeric value encountered

A:\THRILOK\demo\demo
ErrorException
A non-numeric value encountered
http://127.0.0.1:8000/1

    44
    A:\THRILOK\demo\demo\vendor\haruncpi\laravel-id-generator\src\IdGenerator.php
    Illuminate\Foundation\Bootstrap\HandleExceptions
    :50
    43
    A:\THRILOK\demo\demo\vendor\haruncpi\laravel-id-generator\src\IdGenerator.php
    Haruncpi\LaravelIdGenerator\IdGenerator
    :50
    42
    App\Http\Controllers\a
    :11

1 unknown frame
    40
    A:\THRILOK\demo\demo\vendor\laravel\framework\src\Illuminate\Routing\Controller.php
    Illuminate\Routing\Controller
    :54
    39
    Illuminate\Routing\ControllerDispatcher
    :45
    38
    Illuminate\Routing\Route
    :219
    37
    Illuminate\Routing\Route
    :176
    36
    Illuminate\Routing\Router
    :681
    35
    Illuminate\Pipeline\Pipeline
    :130
    34
    Illuminate\Routing\Middleware\SubstituteBindings
    :41
    33
    Illuminate\Pipeline\Pipeline
    :171
    32
    Illuminate\Foundation\Http\Middleware\VerifyCsrfToken
    :76
    31
    Illuminate\Pipeline\Pipeline
    :171
    30
    Illuminate\View\Middleware\ShareErrorsFromSession
    :49
    29
    Illuminate\Pipeline\Pipeline
    :171
    28
    Illuminate\Session\Middleware\StartSession
    :56
    27
    Illuminate\Pipeline\Pipeline
    :171
    26
    Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse
    :37
    25
    Illuminate\Pipeline\Pipeline
    :171
    24
    Illuminate\Cookie\Middleware\EncryptCookies
    :66
    23
    Illuminate\Pipeline\Pipeline
    :171
    22
    Illuminate\Pipeline\Pipeline
    :105
    21
    Illuminate\Routing\Router
    :683
    20
    Illuminate\Routing\Router
    :658
    19
    Illuminate\Routing\Router
    :624
    18
    Illuminate\Routing\Router
    :613
    17
    Illuminate\Foundation\Http\Kernel
    :170
    16
    Illuminate\Pipeline\Pipeline
    :130
    15
    Illuminate\Foundation\Http\Middleware\TransformsRequest
    :21
    14
    Illuminate\Pipeline\Pipeline
    :171
    13
    Illuminate\Foundation\Http\Middleware\TransformsRequest
    :21
    12
    Illuminate\Pipeline\Pipeline
    :171
    11
    Illuminate\Foundation\Http\Middleware\ValidatePostSize
    :27
    10
    Illuminate\Pipeline\Pipeline
    :171
    9
    Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode
    :63
    8
    Illuminate\Pipeline\Pipeline
    :171
    7
    Fideloper\Proxy\TrustProxies
    :57
    6
    Illuminate\Pipeline\Pipeline
    :171
    5
    Illuminate\Pipeline\Pipeline
    :105
    4
    Illuminate\Foundation\Http\Kernel
    :145
    3
    Illuminate\Foundation\Http\Kernel
    :110
    2
    :55
    1
    :21

Illuminate\Foundation\Bootstrap\HandleExceptions::handleError :50
A:\THRILOK\demo\demo\vendor\haruncpi\laravel-id-generator\src\IdGenerator.php:50

    }



    $field = array_key_exists('field', $configArr) ? $configArr['field'] : 'id';

    $prefixLength = strlen($configArr['prefix']);

    $idLength = $configArr['length'] - $prefixLength;

    $whereString = '';



    if (array_key_exists('where', $configArr)) {

        $whereString .= " WHERE ";

        foreach ($configArr['where'] as $row) {

            $whereString .= $row[0] . "=" . $row[1] . " AND ";

        }

    }

    $whereString = rtrim($whereString, 'AND ');





    $totalQuery = sprintf("SELECT count(%s) total FROM %s %s", $field, $configArr['table'], $whereString);

    $total = DB::select($totalQuery);



    if ($total[0]->total) {

        $maxQuery = sprintf("SELECT MAX(SUBSTR(%s,%s,%s)) maxId FROM %s %s",

                    $field, ($prefixLength + 1), $idLength, $configArr['table'], $whereString);

        $maxId = DB::select($maxQuery);

        $maxId = $maxId[1]->maxId + 1;



        return $configArr['prefix'] . str_pad($maxId, $idLength, '0', STR_PAD_LEFT);

    } else {

        return $configArr['prefix'] . str_pad(1, $idLength, '0', STR_PAD_LEFT);

    }

}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.