You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xshop/database/seeders/CustomerSeeder.php

36 lines
906 B
PHTML

7 months ago
<?php
namespace Database\Seeders;
use App\Models\Customer;
use App\Models\State;
7 months ago
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Faker\Factory as Faker;
7 months ago
class CustomerSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
$faker = Faker::create(config('app.faker_locale'));
Customer::factory(35)->create();
foreach (Customer::all() as $customer) {
$s = State::inRandomOrder()->first();
$c = $s->cities()->inRandomOrder()->first();
$customer->addresses()->create([
'state_id' => $s->id,
'city_id' => $c->id,
'zip' => rand(12345, 54321),
'lat' => $c->lat,
'lng' => $c->lng,
'address' =>$faker->address,
]);
}
7 months ago
}
}