Support the ongoing development of Laravel.io →
Laravel
Last updated 2 weeks ago.
1

Hello Meen,

I don't know if you have ever heard about mutators and accessors but it seems what you need.

https://laravel.com/docs/6.x/eloquent-mutators

Hope it help ;)

0

You can use Laravel ID generator package. This package is really simple to use and generate custom ID without any complexity.

For generate id like CUST-00001, CUST-00002 use

$id = IdGenerator::generate(['table' => 'customers', 'length' => 10, 'prefix' =>'CUST-']);

// output CUST-00001, CUST-00002, CUST-00003, ......

For generate id like P-0001, P-0002, M-0001, M-0002 use

$id = IdGenerator::generate(['table' => 'products', 'length' => 6, 'prefix' => $prefix,'reset_on_prefix_change'=>true]);

//output: P-0001, P-0002, M-0001, M-0002, .....

Hope it help :)

Last updated 2 years ago.
1

Sign in to participate in this thread!

Cloudways

Your banner here too?

Meen Meen meenctg Joined 15 Mar 2020

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.