-
-
Save ivandez/ce737459f2d67cbe5c436195b5a8d862 to your computer and use it in GitHub Desktop.
contar productos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function getSerialNumber() | |
{ | |
// Get the last created order | |
$lastOrder = Product::orderBy('created_at', 'desc')->first(); | |
if (!$lastOrder) | |
// We get here if there is no order at all | |
// If there is no number set it to 0, which will be 1 at the end. | |
$number = 0; | |
else | |
$number = substr($lastOrder->serial_number, 3); | |
// If we have SOL0000001 in the database then we only want the number | |
// So the substr returns this 0000001 | |
// Add the string in front and higher up the number. | |
// the %07d part makes sure that there are always 7 numbers in the string. | |
// so it adds the missing zero's when needed. | |
return 'P' . sprintf('%07d', intval($number) + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment