Override specific error

I want to add a text on the error message which is "please refresh the page" I made my TextInput into a unique and disabled which its default value will check the latest order_number and return and increment it. but have one flaw which if someone already have the generated order_number it will return that error message "The order number has been already taken" so maybe I'll just add a message saying "please, refresh the page" or much better generate order_number automatically without refreshing the page using livewire? what do u guys think?
$lastOrder = DB::table('orders')->latest('order_number')->first();

if (!$lastOrder) {
return 'ORD-000001';
}

$lastOrderNumber = $lastOrder->order_number;
$currentOrderNumber = (int) substr($lastOrderNumber, 4); // Extract the numeric part
$nextOrderNumber = $currentOrderNumber + 1;
$numDigits = strlen(str_replace('ORD-', '', $lastOrderNumber)); // Determine the number of digits in the next order number


if($currentOrderNumber >= 1000000) {
$numDigits = (int) $numDigits + 1;
}
return 'ORD-' . str_pad($nextOrderNumber, $numDigits, '0', STR_PAD_LEFT);
$lastOrder = DB::table('orders')->latest('order_number')->first();

if (!$lastOrder) {
return 'ORD-000001';
}

$lastOrderNumber = $lastOrder->order_number;
$currentOrderNumber = (int) substr($lastOrderNumber, 4); // Extract the numeric part
$nextOrderNumber = $currentOrderNumber + 1;
$numDigits = strlen(str_replace('ORD-', '', $lastOrderNumber)); // Determine the number of digits in the next order number


if($currentOrderNumber >= 1000000) {
$numDigits = (int) $numDigits + 1;
}
return 'ORD-' . str_pad($nextOrderNumber, $numDigits, '0', STR_PAD_LEFT);
9 Replies
LeandroFerreira
If I were you, I would create the order number using this approach https://filamentphp.com/docs/2.x/admin/resources/creating-records#customizing-data-before-saving
Filament
Creating records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
Chrysippus
ChrysippusOP2y ago
basically I just want to automate the order_number I want it to listen and get the max(order_number) then + 1 and return it as a value of my TextInput('order_number')
LeandroFerreira
You should generate the order number in the background. Once the order is successfully created, you would display the unique order number to the user 🤷‍♂️
Chrysippus
ChrysippusOP2y ago
it was for admin create just incase they want to create an order. to showcase what order_number they currently have. I just want it to be automated increment(realtime) just incase I created an order for walkin and someone orders online at the same time, we wont have the same order_number, using unique will make it worse since it was disabled
LeandroFerreira
You could also do this in the background customizing the order number before saving
Chrysippus
ChrysippusOP2y ago
should i remove the order_number then? just for overview for admin
LeandroFerreira
You can have an input. If the user enters '0001' in the input field, we will automatically increment the number in the background and display the updated value after saving.
Chrysippus
ChrysippusOP2y ago
I will try your suggestions, thanks
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server