✅ ADMIN PANEL - Controller // Simple CRUD functions public function comments() { $comments = Comment::orderBy('id','desc')->get(); return view('admin.post.comment', compact('comments')); } public function change_comment_status(Request $request, $id) { $comment = Comment::where('id', $id)->first(); if($comment->status == 'Approved') { $comment->status = 'Pending'; } else { $comment->status = 'Approved'; // Send email to commenter when approved $data = [ 'name' => $comment->name, 'email' => $comment->email, 'post_slug' => $comment->post->slug, ]; Mail::to($comment->email)->send(new AdminCommentStatusChangeMail($data)); } $comment->save(); return back()->with('success', 'Comment status changed successfully.'); } public function destroy_comment(Request $request, $id) { $comment = Comment::where('id', $id)->first(); $comment->delete(); return back()->with('success', 'Comment deleted successfully.'); } public function replies() { $replies = Reply::orderBy('id','desc')->get(); return view('admin.post.reply', compact('replies')); } public function change_reply_status(Request $request, $id) { $reply = Reply::where('id', $id)->first(); if($reply->status == 'Approved') { $reply->status = 'Pending'; } else { $reply->status = 'Approved'; // Send email to commenter when approved $data = [ 'name' => $reply->name, 'email' => $reply->email, 'post_slug' => $reply->post->slug, ]; Mail::to($reply->email)->send(new AdminReplyStatusChangeMail($data)); } $reply->save(); return back()->with('success', 'Reply status changed successfully.'); } public function destroy_reply(Request $request, $id) { $reply = Reply::where('id', $id)->first(); $reply->delete(); return back()->with('success', 'Reply deleted successfully.'); } public function admin_reply(Request $request) { $request->validate([ 'reply' => 'required|string', ]); $reply = new Reply(); $reply->post_id = $request->post_id; $reply->comment_id = $request->comment_id; $reply->name = Auth::guard('admin')->user()->name; $reply->email = Auth::guard('admin')->user()->email; $reply->reply = $request->reply; $reply->reply_by = 'Admin'; $reply->status = 'Approved'; $reply->save(); return back()->with('success', 'Replied to comment successfully.'); } ✅ ADMIN PANEL - View - index.blade.php // Like the simple CRUD system ✅ ADMIN PANEL - View - comment.blade.php
@foreach($comments as $comment) @endforeach
SL Post Name & Email Comment Status Action
{{ $loop->iteration }} {{ $comment->post->title }}
Visit Link
{{ $comment->name }}
{{ $comment->email }}
{!! nl2br($comment->comment) !!} @if($comment->status == 'Pending') Pending @elseif($comment->status == 'Approved') Approved @endif
✅ ADMIN PANEL - View - reply.blade.php
@foreach($replies as $reply) @endforeach
SL Post Comment Name & Email Reply Reply By Status Action
{{ $loop->iteration }} {{ $reply->post->title }}
Visit Link
{{ $reply->comment->comment }} @if($reply->reply_by == 'User')
Admin Reply @endif
{{ $reply->name }}
{{ $reply->email }}
{!! nl2br($reply->reply) !!} {{ $reply->reply_by }} @if($reply->status == 'Pending') Pending @elseif($reply->status == 'Approved') Approved @endif @if($reply->reply_by == 'User') @endif
✅ FRONT END - Controller public function blog() { $posts = Post::orderBy('id','desc')->paginate(3); return view('front.blog', compact('posts')); } public function post($slug) { $post = Post::where('slug', $slug)->first(); $next_post = Post::where('id', '>', $post->id)->orderBy('id','asc')->first(); $previous_post = Post::where('id', '<', $post->id)->orderBy('id','desc')->first(); $comments = Comment::where('post_id', $post->id)->where('status', 'Approved')->orderBy('id','desc')->get(); $total_comments = Comment::where('post_id', $post->id)->where('status', 'Approved')->count(); return view('front.post', compact('post', 'next_post', 'previous_post', 'comments', 'total_comments')); } public function post_by_category($slug) { $post_category = PostCategory::where('slug', $slug)->first(); $posts = Post::orderBy('id','desc')->where('post_category_id', $post_category->id)->paginate(3); return view('front.category', compact('posts', 'post_category')); } public function post_by_tag($tag_name) { $posts = Post::where('tags', 'LIKE', '%' . $tag_name . '%')->orderBy('id','desc')->paginate(3); return view('front.tag', compact('posts', 'tag_name')); } public function search(Request $request) { $search_text = $request->search_text; $posts = Post::where('title', 'LIKE', '%' . $search_text . '%') ->orWhere('description', 'LIKE', '%' . $search_text . '%') ->orderBy('id','desc') ->paginate(3); return view('front.search', compact('posts', 'search_text')); } public function comment_store(Request $request) { $validated = $request->validate([ 'name' => 'required', 'email' => 'required|email', 'comment' => 'required', ]); $comment = new Comment(); $comment->post_id = $request->post_id; $comment->name = $request->name; $comment->email = $request->email; $comment->comment = $request->comment; $comment->status = 'Pending'; $comment->save(); // Send email to admin as notification $admin_data = Admin::where('id',1)->first(); $admin_email = $admin_data->email; Mail::to($admin_email)->send(new UserCommentMail($validated)); return redirect()->back()->with('success', 'Comment submitted successfully and is pending for the admin approval.'); } public function reply_store(Request $request) { $validated = $request->validate([ 'name' => 'required', 'email' => 'required|email', 'reply' => 'required', ]); $reply = new Reply(); $reply->post_id = $request->post_id; $reply->comment_id = $request->comment_id; $reply->name = $request->name; $reply->email = $request->email; $reply->reply = $request->reply; $reply->reply_by = 'User'; $reply->status = 'Pending'; $reply->save(); // Send email to admin as notification $admin_data = Admin::where('id',1)->first(); $admin_email = $admin_data->email; Mail::to($admin_email)->send(new UserReplyMail($validated)); return redirect()->back()->with('success', 'Reply submitted successfully and is pending for the admin approval.'); } ✅ FRONT END - View - blog.blade.php // You can do that ✅ FRONT END - View - post.blade.php 👉 Post Tags: $tags = explode(',', $post->tags); foreach($tags as $tag) { $trimmed_tag = trim($tag); if($trimmed_tag) { echo '
  • '.$trimmed_tag.'
  • '; } } 👉 Previous and Next Post: Previous Post Next Post 👉 All Comments Total Comment: {{ (strlen($total_comments) == 1 && $total_comments!=0) ? '0'.$total_comments : $total_comments }} @if($total_comments != 0) @foreach($comments as $comment) $email = trim(strtolower($comment->email)); $hash = md5($email); $gravatar_url = "https://www.gravatar.com/avatar/$hash?s=80&d=mp"; echo 'img'; {{ $comment->created_at->format('F d, Y') }} {{ $comment->name }} {!! nl2br($comment->comment) !!} REPLY @foreach($comment->replies->where('status','Approved') as $reply) $email = trim(strtolower($reply->email)); $hash = md5($email); $gravatar_url = "https://www.gravatar.com/avatar/$hash?s=80&d=mp"; echo 'img'; {{ $reply->created_at->format('F d, Y') }} {{ $reply->name }} @if($reply->reply_by == 'Admin') (Admin) @endif {!! nl2br($reply->reply) !!} @endforeach @endforeach @endif 👉 Submit Comment
    @csrf
    ✅ FRONT END - View - category.blade.php Category: {{ $post_category->name }} ✅ FRONT END - View - tag.blade.php Tag: {{ $tag_name }} ✅ FRONT END - View - search.blade.php Search By: {{ $search_text }} ✅ Sidebar
    toArray(); $tags_array = []; foreach($all_tags as $tags) { $tags_split = explode(',', $tags); foreach($tags_split as $tag) { $trimmed_tag = trim($tag); if($trimmed_tag && !in_array($trimmed_tag, $tags_array)) { $tags_array[] = $trimmed_tag; } } } @endphp @foreach($tags_array as $tag)
  • {{ $tag }}
  • @endforeach ✅ Model: Post public function post_category() { return $this->belongsTo(PostCategory::class); } public function admin() { return $this->belongsTo(Admin::class); } public function comments() { return $this->hasMany(Comment::class); } public function replies() { return $this->hasMany(Reply::class); } ✅ Model: PostCategory public function posts() { return $this->hasMany(Post::class); } ✅ Model: Comment public function post() { return $this->belongsTo(Post::class); } public function replies() { return $this->hasMany(Reply::class); } ✅ Model: Reply public function comment() { return $this->belongsTo(Comment::class); } public function post() { return $this->belongsTo(Post::class); }