feat: implement blog homepage widgets including hero carousel, category highlights, and sidebar components
This commit is contained in:
@@ -110,6 +110,75 @@ class BlogController extends Controller
|
||||
// Kategorileri al (filtreleme için)
|
||||
$categories = class_exists(\App\Models\BlogCategory::class) ? \App\Models\BlogCategory::where('is_active', true)->orderBy('sort_order')->get() : collect();
|
||||
|
||||
// Elemis Widget'ları için veri hazırlığı
|
||||
$carouselPosts = collect();
|
||||
$highlightCategories = collect();
|
||||
$popularPosts = collect();
|
||||
$sidebarCategories = collect();
|
||||
$tags = collect();
|
||||
|
||||
if (!$request->ajax()) {
|
||||
if (class_exists(Blog::class)) {
|
||||
// Karusel: Öne çıkarılan ya da en güncel 5 yazı
|
||||
$carouselPosts = Blog::with(['category', 'author'])
|
||||
->published()
|
||||
->featured()
|
||||
->latest('published_at')
|
||||
->take(5)
|
||||
->get();
|
||||
if ($carouselPosts->isEmpty()) {
|
||||
$carouselPosts = Blog::with(['category', 'author'])
|
||||
->published()
|
||||
->latest('published_at')
|
||||
->take(5)
|
||||
->get();
|
||||
}
|
||||
|
||||
// Popüler Yazılar: En çok okunan 3 yazı
|
||||
$popularPosts = Blog::with(['category', 'author'])
|
||||
->published()
|
||||
->orderBy('view_count', 'desc')
|
||||
->take(3)
|
||||
->get();
|
||||
|
||||
// Etiket Bulutu: Tüm yayınlanan yazılardaki benzersiz etiketler
|
||||
$allTags = Blog::published()
|
||||
->whereNotNull('tags')
|
||||
->pluck('tags');
|
||||
$tagsCollected = collect();
|
||||
foreach ($allTags as $postTags) {
|
||||
if (is_array($postTags)) {
|
||||
foreach ($postTags as $tag) {
|
||||
$tagsCollected->push($tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
$tags = $tagsCollected->unique()->take(15);
|
||||
}
|
||||
|
||||
if (class_exists(\App\Models\BlogCategory::class)) {
|
||||
// Hoş Geldiniz bölümü altındaki 3'lü kategori vurgusu
|
||||
$highlightCategories = \App\Models\BlogCategory::where('is_active', true)
|
||||
->withCount('blogs')
|
||||
->has('blogs')
|
||||
->orderBy('sort_order')
|
||||
->take(3)
|
||||
->get();
|
||||
if ($highlightCategories->count() < 3) {
|
||||
$highlightCategories = \App\Models\BlogCategory::where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->take(3)
|
||||
->get();
|
||||
}
|
||||
|
||||
// Sidebar Kategorileri: Yazı sayısıyla birlikte
|
||||
$sidebarCategories = \App\Models\BlogCategory::where('is_active', true)
|
||||
->withCount('blogs')
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->ajax()) {
|
||||
return view('blog.partials.posts', [
|
||||
'posts' => $posts
|
||||
@@ -122,6 +191,11 @@ class BlogController extends Controller
|
||||
'settings' => $settings,
|
||||
'posts' => $posts,
|
||||
'categories' => $categories,
|
||||
'carouselPosts' => $carouselPosts,
|
||||
'highlightCategories' => $highlightCategories,
|
||||
'popularPosts' => $popularPosts,
|
||||
'sidebarCategories' => $sidebarCategories,
|
||||
'tags' => $tags,
|
||||
'renderedHeader' => $renderedHeader,
|
||||
'renderedFooter' => $renderedFooter,
|
||||
'meta' => [
|
||||
|
||||
Reference in New Issue
Block a user