Assume we have a customers table and there is a field like a phone number. Now we want to seed data in laravel using database seeder. To do that, we can use phoneNumber helper. I will show you the example of faker mobile number laravel.

So if you are looking for faker phone number format laravel then this tutorial is for you. So let's see the example code of faker laravel phone number:

<?php

use App\Models\Customer;
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;

class CustomerSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        $faker = Faker::create();

        for ($i=1; $i < 101 ; $i++) { 
            $customer = new Customer;
            $customer->phone = $faker->phoneNumber;
            $customer->save();
        }  
    }
}

 

If you are in Laravel 9 version, then you can use like this:

<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
 */
class CompanyFactory extends Factory
{
    public function definition()
    {
        return [
            'phone_number' => fake()->phoneNumber()
        ];
    }
}

 

See all the available faker phone number helpers from below:

 

phoneNumber             // '201-886-0269 x3767'
tollFreePhoneNumber     // '(888) 937-7238'
e164PhoneNumber     // '+27113456789'

 

Read also: Laravel Faker Random 10 Digit Number Example

 

Conclusion

I have tried to discuss the clear concept of the laravel faker phone. Now we know faker mobile number laravel. Hope this faker phone number format laravel tutorial will help you.