In order to do that you would need to keep a list of the random numbers you have generated, if your new random number is in your list generate a new random number:
$uniquePizzaNumber = function() {
static $usedNumbers = [];
do {
$pizza = $faker->numberBetween(0,1000);
} while (in_array($usedNumbers, $pizza);
return $pizza;
}
This will work so long as you call the factory only once (e.g. in a migration or using tinker) if you want to call it multiple times you will have to check the database for a conflict rather than the $usedNumbers array.
$uniquePizzaNumber = function() {
do {
$pizza = $faker->numberBetween(0,1000);
} while (DB::table('pizza_table')->where('pizza', $pizza)->count());
return $pizza;
}
As an alternative you could just make the sequential for testing, be much easier.