- Introduced a many-to-many relationship in PartnerMedia for announcements. - Added a has-many relationship in User for news authored by the user. - Implemented an active scope in User for filtering active users.
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Announcement;
|
|
use App\Models\AnnouncementUser;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AnnouncementUser>
|
|
*/
|
|
class AnnouncementUserFactory extends Factory
|
|
{
|
|
protected $model = AnnouncementUser::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,
|
|
]);
|
|
}
|
|
}
|