How to generate custom ID in Laravel - Laravel ID generator
Vložit
- čas přidán 21. 11. 2019
- In this video, I have shown you how to generate custom ID in Laravel Framework with Laravel ID generator package.
For more example please visit: laravelarticle.com/laravel-cu...
#Laravel #IdGenerator
I love it. Very Simple and easy to implement. Thanks
Thank you for feedback
thanks dude it help me so mucc i hope i can run this method on laravel 8
hey your video is great but I am inserting multiple data to the database at the same time and i would like all of them to have same id.How can I go about it?
thanks
It's pleasure
I got error, i want to insert in Orders table not User table, but the errors say “column not found unknow trx(field for keep and save id generator) in where clause “ SELECT count* As aggregate From Users where trx
how to use with multiple databases ?
how can I make that auto restart at 1 when the new year?
On prefix change reset id support added (v1.0.5). Please check the documentation. laravelarticle.com/laravel-custom-id-generator
hi how about i need to put the unique generated ID from the other column, it always going to the id column
Check out latest relaese.
link please?
v1.0.4
github.com/haruncpi/laravel-id-generator
@@LaravelArticle how to fix A non-numeric value encountered
@@JayRagnamTV If your id mix with string+digit then your field data type must be varchar
i got the error when i go for the next increment like INV-00002 shows A non-numeric value encountered
Please make sure your field type is varchar according to your id format.
@@LaravelArticle i have an error like that too, and my field type is varchar, but still got that error, how i can fix this??
@@riandemonfox8880 i got that too, pls reply
how to use with postgresql
Please try the latest version.
there's an error after storing data for the first time, the second tim i got error A non-numeric value encountered
i already fixed this, when i use length = 4 i encountered the error. try change the length to 10 (maybe 6 work as well)
Exception
table field type is bigint but prefix is string
how to fix it? when i change type data id integer to varchar : error mysql
Please let me know, what is your id format and field type?
@@LaravelArticle id, bigint, 11, AI, primary
Don't use AI, if your field type int then do not use id formation like INV-10001 or 100-4667 or P-0001. Please let me know what is your expected id format.
@@LaravelArticle but I also have an error like that, I have tried to use type string / char / text but still get the error "table field type is bigint but prefix is string", like this stackoverflow.com/questions/65642455/idgenerator-laravel-8-how-to-fix-exception-table-field-type-is-bigint-but-pref
help me, thanks
@@yahikkonr6350 By default it uses id column. Your solution is given stackoverflow.com/questions/65642455/idgenerator-laravel-8-how-to-fix-exception-table-field-type-is-bigint-but-pref/65643282#65643282
hi! its really helpful, butt there is a problem. it generate same id everytime.
$config = [
'table' => 'visitor',
'length' => 9,
'prefix' => date('y')
];
return $vid = IdGenerator::generate($config);
MY CODE
how i can use restart every year but i need this output: 0001-2020
Code: $id = IdGenerator::generate(['table' => 'orders','field'=>'c_interno', 'length' => 9, 'prefix' =>date('-Y'),'reset_on_prefix_change'=>true]);
You can't. Doable 2020-0001
do u find any solution??
@@anisawadi3453 i save $id_generate = IdGenerator::generate(['table' => 'orders','field'=>'c_interno', 'length' => 9, 'prefix' =>date('-Y'),'reset_on_prefix_change'=>true]);
and for show in view
$id_generate = explode('-',$order->c_interno);
$codigo = $id_generate[1];
$year = $id_generate[0];
This is not working with Laravel 8
Is there any way that this package can work with Laravel 8 ?
Not working is not enough message about it’s working or not. Let us know what you are tring and what's the actual error with clear example code in GitHub issue.
@@LaravelArticle I am also facing this issue with laravel 8. It's not incrementing the same value are inserting in the database table. is there are any way to work with laravel 8.
Please try the latest version of Laravel ID generator
@@LaravelArticle Hello, this package doesnt work correctly in Laravel 8. I doesnt get the max ID value from the id table. It creates values with ids from 1-10 and then it starts from 1 again. Example: 210001, 210002,210003,...,210010,210001,210002. I needed a custom ID field in the db and I would like to use the unique ID value of every row to create such and id but its not creating unique values. I'm using the latest version.