diff --git a/app/Http/Controllers/BlogController.php b/app/Http/Controllers/BlogController.php index 7a57da2..6bc1218 100644 --- a/app/Http/Controllers/BlogController.php +++ b/app/Http/Controllers/BlogController.php @@ -13,15 +13,35 @@ use Illuminate\Support\Facades\Validator; class BlogController extends Controller { - public function index() + public function index(Request $request) { $settings = class_exists(Setting::class) ? (Setting::query()->first()) : null; - $posts = class_exists(Blog::class) + + $query = class_exists(Blog::class) ? Blog::with(['category', 'author']) ->withCount('comments') ->published() - ->latest('published_at') - ->paginate(12) + : null; + + // Author filtresi + if ($query && $request->has('author') && $request->author) { + $query = $query->where('author_id', $request->author); + } + + // Category filtresi + if ($query && $request->has('category') && $request->category) { + $query = $query->whereHas('category', function($q) use ($request) { + $q->where('slug', $request->category); + }); + } + + // Tag filtresi + if ($query && $request->has('tag') && $request->tag) { + $query = $query->whereJsonContains('tags', $request->tag); + } + + $posts = $query + ? $query->latest('published_at')->paginate(12) : collect(); // Render Header Template - En son aktif olan header template'i kullan @@ -156,6 +176,49 @@ class BlogController extends Controller ], ]); } + + public function storeComment(Request $request, string $slug) + { + if (!class_exists(Blog::class) || !class_exists(BlogComment::class)) { + abort(404); + } + + $post = Blog::published() + ->where('slug', $slug) + ->firstOrFail(); + + if (!$post->allow_comments) { + return redirect()->route('blog.show', $slug) + ->with('error', __('blog.comments_disabled')); + } + + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:255', + 'email' => 'required|email|max:255', + 'content' => 'required|string|min:10', + 'parent_id' => 'nullable|exists:blog_comments,id', + ]); + + if ($validator->fails()) { + return redirect()->route('blog.show', $slug) + ->withErrors($validator) + ->withInput(); + } + + $comment = BlogComment::create([ + 'blog_id' => $post->id, + 'name' => $request->name, + 'email' => $request->email, + 'content' => $request->content, + 'parent_id' => $request->parent_id, + 'status' => 'pending', // Yorumlar onay bekliyor olarak kaydedilir + 'ip_address' => $request->ip(), + 'user_agent' => $request->userAgent(), + ]); + + return redirect()->route('blog.show', $slug) + ->with('success', __('blog.comment_submitted')); + } } diff --git a/lang/en/blog.php b/lang/en/blog.php index 0f06497..c6d745a 100644 --- a/lang/en/blog.php +++ b/lang/en/blog.php @@ -85,4 +85,23 @@ return [ 'slug_unique' => 'This URL slug is already in use.', 'content_required' => 'Content field is required.', 'author_required' => 'Author field is required.', + + // Blog post page + 'by' => 'By', + 'comments' => 'Comments', + 'share' => 'Share', + 'author' => 'Author', + 'all_posts' => 'All Posts', + 'you_might_also_like' => 'You Might Also Like', + 'read_more' => 'Read More', + 'reply' => 'Reply', + 'share_thoughts' => 'Would you like to share your thoughts?', + 'comment_form_description' => 'Your email address will not be published. Required fields are marked *', + 'name' => 'Name', + 'email' => 'Email', + 'website' => 'Website', + 'comment' => 'Comment', + 'submit' => 'Submit', + 'comment_submitted' => 'Your comment has been submitted. It will be published after approval.', + 'comments_disabled' => 'Comments are disabled for this blog post.', ]; diff --git a/lang/tr/blog.php b/lang/tr/blog.php index 14a5d05..7fb3797 100644 --- a/lang/tr/blog.php +++ b/lang/tr/blog.php @@ -85,4 +85,23 @@ return [ 'slug_unique' => 'Bu URL yolu zaten kullanılıyor.', 'content_required' => 'İçerik alanı zorunludur.', 'author_required' => 'Yazar alanı zorunludur.', + + // Blog post page + 'by' => 'Yazar', + 'comments' => 'Yorum', + 'share' => 'Paylaş', + 'author' => 'Yazar', + 'all_posts' => 'Tüm Yazılar', + 'you_might_also_like' => 'Bunları da Beğenebilirsiniz', + 'read_more' => 'Devamını Oku', + 'reply' => 'Yanıtla', + 'share_thoughts' => 'Düşüncelerinizi paylaşır mısınız?', + 'comment_form_description' => 'E-posta adresiniz yayınlanmayacaktır. Zorunlu alanlar * ile işaretlenmiştir.', + 'name' => 'Ad', + 'email' => 'E-posta', + 'website' => 'Web Sitesi', + 'comment' => 'Yorum', + 'submit' => 'Gönder', + 'comment_submitted' => 'Yorumunuz gönderildi. Onaylandıktan sonra yayınlanacaktır.', + 'comments_disabled' => 'Bu blog yazısında yorumlar devre dışı bırakılmıştır.', ]; diff --git a/resources/views/blog/index.blade.php b/resources/views/blog/index.blade.php index a87d45e..038d1f3 100644 --- a/resources/views/blog/index.blade.php +++ b/resources/views/blog/index.blade.php @@ -1,31 +1,196 @@ @extends('layouts.site') @section('content') -
-
-
- @forelse($posts as $post) - - @empty -

{{ __('blog.empty') }}

- @endforelse -
- - @if(method_exists($posts, 'links')) - {{ $posts->links() }} - @endif -
+
+
+
+
+

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

+

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

+
+ +
+ +
+
+ + +
+
+
+
+
+ @forelse($posts as $index => $post) + @php + $title = method_exists($post, 'translate') ? $post->translate('title') : $post->title; + $excerpt = method_exists($post, 'translate') ? $post->translate('excerpt') : ($post->excerpt ?? ''); + $categoryName = $post->category ? $post->category->name : ''; + $categorySlug = $post->category ? $post->category->slug : ''; + $publishedDate = $post->published_at ? $post->published_at->format('d M Y') : $post->created_at->format('d M Y'); + $imageUrl = $post->featured_image ? asset('storage/' . $post->featured_image) : asset('assets/img/photos/b1.jpg'); + $blogUrl = route('blog.show', $post->slug); + $commentCount = $post->comments_count ?? 0; + $authorName = $post->author ? $post->author->name : ''; + @endphp + + @if($index < 3) + {{-- İlk 3 blog yazısı classic-view formatında --}} + + + @endif + @empty +
+

{{ __('blog.empty') }}

+
+ @endforelse +
+ + + @if($posts->count() > 3) +
+
+ @foreach($posts as $index => $post) + @if($index >= 3) + @php + $title = method_exists($post, 'translate') ? $post->translate('title') : $post->title; + $excerpt = method_exists($post, 'translate') ? $post->translate('excerpt') : ($post->excerpt ?? ''); + $categoryName = $post->category ? $post->category->name : ''; + $categorySlug = $post->category ? $post->category->slug : ''; + $publishedDate = $post->published_at ? $post->published_at->format('d M Y') : $post->created_at->format('d M Y'); + $imageUrl = $post->featured_image ? asset('storage/' . $post->featured_image) : asset('assets/img/photos/b4.jpg'); + $blogUrl = route('blog.show', $post->slug); + $commentCount = $post->comments_count ?? 0; + @endphp + +
+
+
+ + {{ $title }} + +
+
{{ __('blog.read_more') }}
+
+
+
+
+ @if($categoryName) + + @endif + +

+ {{ $title }} +

+
+ +
+

{{ \Illuminate\Support\Str::limit($excerpt, 120) }}

+
+ +
+ + + +
+ +
+ + @endif + @endforeach +
+ +
+ + @endif + + {{-- Pagination --}} + @if(method_exists($posts, 'links') && $posts->hasPages()) +
+ {{ $posts->links() }} +
+ @endif +
+ +
+ +
+ +
@endsection - - diff --git a/resources/views/blog/show.blade.php b/resources/views/blog/show.blade.php index ad4bc94..8ca6e3e 100644 --- a/resources/views/blog/show.blade.php +++ b/resources/views/blog/show.blade.php @@ -352,6 +352,16 @@

{{ __('blog.share_thoughts') }}

{{ __('blog.comment_form_description') }}

+ @if(session('success')) +
+ {{ session('success') }} +
+ @endif + @if(session('error')) +
+ {{ session('error') }} +
+ @endif
@csrf @@ -363,10 +373,6 @@ -
- - -