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 ;)
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 :)
meenctg liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community