$array, array $array1) */ class PlatformChannelPost extends Model { /** @use HasFactory> */ use HasFactory; protected $fillable = [ 'platform', 'channel_id', 'channel_name', 'post_id', 'url', 'title', 'posted_at', ]; /** * @return array */ protected function casts(): array { return [ 'posted_at' => 'datetime', 'platform' => PlatformEnum::class, ]; } public static function urlExists(PlatformEnum $platform, string $channelId, string $url): bool { return self::where('platform', $platform) ->where('channel_id', $channelId) ->where('url', $url) ->exists(); } public static function duplicateExists(PlatformEnum $platform, string $channelId, ?string $url, ?string $title): bool { if (! $url && ! $title) { return false; } return self::where('platform', $platform) ->where('channel_id', $channelId) ->where(function ($query) use ($url, $title) { if ($url) { $query->orWhere('url', $url); } if ($title) { $query->orWhere('title', $title); } }) ->exists(); } public static function storePost(PlatformEnum $platform, string $channelId, ?string $channelName, string $postId, ?string $url, ?string $title, ?\DateTime $postedAt = null): self { return self::updateOrCreate( [ 'platform' => $platform, 'channel_id' => $channelId, 'post_id' => $postId, ], [ 'channel_name' => $channelName, 'url' => $url, 'title' => $title, 'posted_at' => $postedAt ?? now(), ] ); } }