$array, array $array1) */ class PlatformChannelPost extends Model { /** @use HasFactory> */ use HasFactory; protected $fillable = [ 'platform_channel_id', 'post_id', 'url', 'title', 'posted_at', ]; /** * @return array */ protected function casts(): array { return [ 'posted_at' => 'datetime', ]; } /** * @return BelongsTo */ public function platformChannel(): BelongsTo { return $this->belongsTo(PlatformChannel::class); } public static function duplicateExists(PlatformChannel $channel, ?string $url, ?string $title): bool { if (! $url && ! $title) { return false; } return self::where('platform_channel_id', $channel->id) ->where(function ($query) use ($url, $title) { if ($url) { $query->orWhere('url', $url); } if ($title) { $query->orWhere('title', $title); } }) ->exists(); } public static function storePost(PlatformChannel $channel, string $postId, ?string $url, ?string $title, ?\DateTime $postedAt = null): self { return self::updateOrCreate( [ 'platform_channel_id' => $channel->id, 'post_id' => $postId, ], [ 'url' => $url, 'title' => $title, 'posted_at' => $postedAt ?? now(), ] ); } }