I have some SQL code which generates random numbers using the following technique:
DECLARE @Random1 INT, @Random2 INT, @Random3 INT, @Random4 INT, @Random5 I
For Laravel:
public function generatUniqueId() { $rand = rand(10000, 99999); $itemId = $rand; while (true) { if (!BookItem::whereBookItemId($itemId)->exists()) { break; } $itemId = rand(10000, 99999); } return $itemId; }