Rainieren
1 year ago

Laravel - Create order_nr sequence

Posted 1 year ago by Rainieren

Hello, I'm trying to create an order_nr sequence, for instance, ORD000001, ORD000002. I'm trying to do this in my seeder. In my OrderSeederTable, I have a foreach loop which does the following:

foreach(range(1,25) as $index)
        {
            DB::table('orders')->insert([

                'user_id' => rand(1,25),
                'webshop_id' => rand(1, 20), 
                'order_nr' => $faker->unique()->randomNumber($nbDigits = NULL, $strict = false),
                'price_sum' => 1234.56,
                'status' => $faker->randomElement(['paid', 'pending', 'failed']),
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),

            ]);
        }

How can I make the order_nr in that sequence? That every order_nr goes +1. with ORD in front of it? Currently i'm just renerating random numbers. Thanks in advance!

Please sign in or create an account to participate in this conversation.