Skip to content

Commit 630d4ee

Browse files
committedDec 19, 2024
factories updates
1 parent e898d87 commit 630d4ee

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed
 

‎database/factories/PropertyAddressFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function definition(): array
2020
{
2121
return [
2222
'city_id' => City::inRandomOrder()->firstOrFail()->id,
23-
'property_id' => Property::factory(),
23+
'property_id' => null,
2424
'address_line' => fake()->streetAddress()
2525
];
2626
}

‎database/factories/PropertyFactory.php

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use App\Models\User;
77
use App\Models\PropertyStatus;
88
use App\Services\TextUniqueSlugService;
9+
use App\Models\PropertyAddress;
10+
use App\Models\Property;
911

1012
/**
1113
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Property>
@@ -30,4 +32,13 @@ public function definition(): array
3032
'status_id' => PropertyStatus::inRandomOrder()->firstOrFail()->id,
3133
];
3234
}
35+
36+
public function configure(): static
37+
{
38+
return $this->afterMaking(function (Property $property) {
39+
PropertyAddress::factory()->make(['property_id' => $property->id]);
40+
})->afterCreating(function (Property $property) {
41+
PropertyAddress::factory()->create(['property_id' => $property->id]);
42+
});
43+
}
3344
}

‎database/seeders/FakerSeeder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Support\Facades\DB;
77
use Illuminate\Support\Facades\Schema;
88
use App\Models\User;
9-
use App\Models\PropertyAddress;
9+
use App\Models\Property;
1010

1111
class FakerSeeder extends Seeder
1212
{
@@ -19,7 +19,7 @@ public function run()
1919
{
2020
User::factory()->count(58)->create();
2121

22-
//this will make both properties and property
23-
PropertyAddress::factory()->count(127)->create();
22+
//this will create properties
23+
Property::factory()->count(127)->create();
2424
}
2525
}

0 commit comments

Comments
 (0)
Please sign in to comment.