- Introduced the AnnouncementMedia model, removing soft deletes for a simplified structure. - Added AnnouncementMediaFactory for generating test data with relationships to Announcement and PartnerMedia. - Created migration for the announcement_media table without soft deletes.
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Announcement;
|
|
use App\Models\AnnouncementMedia;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AnnouncementMedia>
|
|
*/
|
|
class AnnouncementMediaFactory extends Factory
|
|
{
|
|
protected $model = AnnouncementMedia::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'announcement_id' => Announcement::factory(),
|
|
'partner_media_id' => PartnerMedia::factory(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Indicate that the announcement user is for a specific announcement.
|
|
*/
|
|
public function forAnnouncement(Announcement $announcement): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'announcement_id' => $announcement->id,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the announcement user is for a specific partner media.
|
|
*/
|
|
public function forPartnerMedia(PartnerMedia $partnerMedia): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'partner_media_id' => $partnerMedia->id,
|
|
]);
|
|
}
|
|
}
|