| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace Database\Seeders;
- use App\Models\User;
- use App\Models\Category;
- use App\Models\FormData;
- use App\Models\Comments;
- use Illuminate\Database\Console\Seeds\WithoutModelEvents;
- use Illuminate\Database\Seeder;
- class DatabaseSeeder extends Seeder
- {
- use WithoutModelEvents;
- /**
- * Seed the application's database.
- */
- public function run(): void
- {
- User::where('email', 'test@example.com')->delete();
- $user = User::factory()->create([
- 'name' => 'Test User',
- 'email' => 'test@example.com',
- 'password' => bcrypt('password'),
- ]);
- $categories = Category::factory()->count(5)->create();
- FormData::factory()->count(50)->create()->each(function ($formData) use ($categories, $user) {
- $formData->category()->associate($categories->random());
- $formData->save();
- Comments::factory()->count(rand(0, 3))->create([
- 'commentable_id' => $formData->id,
- 'commentable_type' => FormData::class,
- 'user_id' => rand(0, 1) ? $user->id : null,
- ]);
- });
- $this->command->info('Database seeded successfully!');
- }
- }
|