I'm currently trying to create a unique sequence number when the user reaches the create method. Order numbers are generated in the same way in the seed and should look the same as
Seeder
foreach(range(1,25) as $index)
{
DB::table('orders')->insert([
'user_id' => rand(1,25),
'order_nr' => '#' . sprintf("%08d", $index),
'price_sum' => $faker->randomNumber($nbDigits = 4, $strict = false) . '.' . $faker->randomNumber($nbDigits = 2, $strict = false),
'status' => $faker->randomElement(['paid', 'pending', 'failed']),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
]);
}
Order numbers are as follows: #00000001or #00000002. Now that the user reaches the create method in my controller, you need to create a new unique sequence number in this sequence. How can i achieve this? Currently, the controller is as follows:
public function create()
{
$order = new Order;
$order->user_id = Auth()->id();
$order->order_nr =
dd($order);
return view('steps.order');
}
He must check the last order number and create it with +1 on this order number. Say, for example, there are 25 orders, and the last number # 00000025, which should be created next, should be # 00000026. How can I achieve this?