artworkId); $user = User::find($this->userId); if (! $artwork || ! $user) { return; } // If post already exists for this artwork, skip (idempotent) $exists = Post::where('user_id', $user->id) ->where('type', Post::TYPE_UPLOAD) ->whereHas('targets', fn ($q) => $q->where('target_type', 'artwork')->where('target_id', $artwork->id)) ->exists(); if ($exists) { return; } DB::transaction(function () use ($artwork, $user, $hashtagService) { $post = Post::create([ 'user_id' => $user->id, 'type' => Post::TYPE_UPLOAD, 'visibility' => Post::VISIBILITY_PUBLIC, 'body' => null, 'status' => Post::STATUS_PUBLISHED, ]); PostTarget::create([ 'post_id' => $post->id, 'target_type' => 'artwork', 'target_id' => $artwork->id, ]); }); Log::info("AutoUploadPostJob: created upload post for artwork #{$this->artworkId} by user #{$this->userId}"); } }