status !== 'published') { return; } // Check if auto-publish setting is enabled if (!Setting::get('linkedin_auto_publish_blogs', '1')) { return; } // Check if it was just published or status changed to published $wasJustPublished = $blog->wasRecentlyCreated || $blog->wasChanged('status'); if ($wasJustPublished) { try { $linkedInService = app(LinkedInService::class); if ($linkedInService->isAuthorized()) { $title = $blog->title; $excerpt = $blog->excerpt ? strip_tags($blog->excerpt) : Str::limit(strip_tags($blog->content), 200); $url = url('/blog/' . $blog->slug); $result = $linkedInService->sharePost($title, $excerpt, $url); if ($result['success']) { Log::info("Blog [#{$blog->id}] LinkedIn'de otomatik paylaşıldı.", ['post_id' => $result['post_id'] ?? null]); } else { Log::warning("Blog [#{$blog->id}] LinkedIn paylaşımı başarısız: " . $result['message']); } } } catch (\Throwable $e) { Log::error("BlogObserver LinkedIn auto-post error: " . $e->getMessage()); } } } }