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

33 lines
817 B
PHP

<?php
namespace Database\Seeders;
use App\Models\Customer;
use App\Models\State;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class CustomerSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
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' => 'some address',
]);
}
}
}