Assume you are going to seed dummy data for your product and there is a mandatory price field. How do you insert a price with a Laravel faker? You are going to save 100 data and you need a different price for every product. In this tutorial, I will show you how to generate a random number and seed with Laravel database seeder example.

From this example, you will see faker random number in range in Laravel. So let's see the example code of faker random 10 digit number:

Database\Seeders\ProductSeeder.php

<?php

use App\Models\Product;
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class ProductSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = Faker::create();
        
        for ($i=1; $i < 101 ; $i++) { 
            $sku = random_int(1000000000,9999999999); //for 10 digit
            $product = new Product;
            $product->sku = $sku;
            $product->price = $faker->numberBetween(100,500); //it will create price within 100 to 500
            $product->save();
        } 
    }
}

 

Conclusion

I have tried to discuss the clear concept of laravel faker random number 10 digits. Now we know faker random number in range. Hope faker random 10 digit number tutorial will help you.