From b36ccf298bc0bd319f74801357696f0071b6f767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Sun, 24 May 2026 10:37:32 +0300 Subject: [PATCH] feat: implement blog homepage widgets including hero carousel, category highlights, and sidebar components --- app/Http/Controllers/BlogController.php | 74 ++++ resources/views/blog/index.blade.php | 227 +++++++++-- resources/views/blog/partials/posts.blade.php | 130 +++--- resources/views/blog/show.blade.php | 372 +++--------------- 4 files changed, 375 insertions(+), 428 deletions(-) diff --git a/app/Http/Controllers/BlogController.php b/app/Http/Controllers/BlogController.php index 58480a9..5402214 100644 --- a/app/Http/Controllers/BlogController.php +++ b/app/Http/Controllers/BlogController.php @@ -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' => [ diff --git a/resources/views/blog/index.blade.php b/resources/views/blog/index.blade.php index c73cb7c..2d4c829 100644 --- a/resources/views/blog/index.blade.php +++ b/resources/views/blog/index.blade.php @@ -2,33 +2,112 @@ @extends('layouts.site') @section('content') -
-
-
-
-

{{ __('blog.meta-index-title') }}

-

{{ __('blog.meta-index-description') }}

+
+
+ + + @if(isset($carouselPosts) && $carouselPosts->count() > 0) +
+
+
+ @foreach($carouselPosts as $cPost) + @php + $cTitle = method_exists($cPost, 'translate') ? $cPost->translate('title') : $cPost->title; + $cExcerpt = method_exists($cPost, 'translate') ? $cPost->translate('excerpt') : ($cPost->excerpt ?? ''); + $cCategoryName = $cPost->category ? $cPost->category->name : ''; + $cCategorySlug = $cPost->category ? $cPost->category->slug : ''; + $cDate = $cPost->published_at ? $cPost->published_at->format('d M Y') : $cPost->created_at->format('d M Y'); + $cImage = $cPost->featured_image ? asset('storage/' . $cPost->featured_image) : asset('assets/img/photos/tb1.jpg'); + $cUrl = route('blog.show', $cPost->slug); + @endphp +
+
+ + {{ $cTitle }} + +
+ @if($cCategoryName) + {{ $cCategoryName }} + @endif +

+ {{ \Illuminate\Support\Str::limit($cTitle, 60) }} +

+
    + + @if($cPost->author) + + @endif +
+
+
+
+ @endforeach +
-
- -
- -
- + @endif -
-
+
-
+
+

+ Merhaba! Biz Trunçgil. Blogumuza hoş geldiniz. Burada web tasarım, yazılım geliştirme ve teknolojik yeniliklere dair ipuçlarını ve deneyimlerimizi paylaşıyoruz. +

+
+
+ + + @if(isset($highlightCategories) && $highlightCategories->count() > 0) +
+ @foreach($highlightCategories as $index => $hCat) + @php + $images = ['assets/img/photos/f1.jpg', 'assets/img/photos/f2.jpg', 'assets/img/photos/f3.jpg']; + $hImg = asset($images[$index % 3]); + $hUrl = route('blog.index', ['category' => $hCat->slug]); + @endphp +
+
+
+ + {{ $hCat->name }} + +
+
Keşfet
+
+
+ +
+
+ @endforeach +
+ @endif + + +
+ + +
+ @if(isset($categories) && $categories->count() > 0) -
- - {{ __('blog.all_categories', ['default' => 'Tümü']) }} +
+ + Tümü @foreach($categories as $category) - + {{ $category->name }} @endforeach @@ -39,12 +118,94 @@ @include('blog.partials.posts')
- + + + +
-
- -
+
@push('styles')