comment moderation improvments
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Comment;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CommentModerationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of comments for moderation.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Comment::with(['user', 'product', 'moderator']);
|
||||
|
||||
// Filter by status
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->status);
|
||||
} else {
|
||||
// Default to showing pending comments
|
||||
$query->where('status', 'pending');
|
||||
}
|
||||
|
||||
// Search in comment body or user name
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('body', 'like', "%{$search}%")
|
||||
->orWhereHas('user', function ($userQuery) use ($search) {
|
||||
$userQuery->where('name', 'like', "%{$search}%")
|
||||
->orWhere('email', 'like', "%{$search}%");
|
||||
})
|
||||
->orWhereHas('product', function ($productQuery) use ($search) {
|
||||
$productQuery->where('name', 'like', "%{$search}%");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Get counts for tabs
|
||||
$pendingCount = Comment::where('status', 'pending')->count();
|
||||
$approvedCount = Comment::where('status', 'approved')->count();
|
||||
$rejectedCount = Comment::where('status', 'rejected')->count();
|
||||
|
||||
$comments = $query->latest()->paginate(20);
|
||||
|
||||
return view('moderation.comments.index', compact(
|
||||
'comments',
|
||||
'pendingCount',
|
||||
'approvedCount',
|
||||
'rejectedCount'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing a comment.
|
||||
*/
|
||||
public function edit(Comment $comment)
|
||||
{
|
||||
$comment->load(['user', 'product', 'moderator']);
|
||||
|
||||
return view('moderation.comments.edit', compact('comment'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified comment.
|
||||
*/
|
||||
public function update(Request $request, Comment $comment)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'body' => ['required', 'string', 'max:1000'],
|
||||
]);
|
||||
|
||||
$comment->update($validated);
|
||||
|
||||
return redirect()->route('moderation.comments.index')
|
||||
->with('success', 'Comment updated successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve a comment.
|
||||
*/
|
||||
public function approve(Request $request, Comment $comment)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'moderation_note' => ['nullable', 'string', 'max:500'],
|
||||
]);
|
||||
|
||||
$comment->update([
|
||||
'status' => 'approved',
|
||||
'moderated_by' => auth()->id(),
|
||||
'moderated_at' => now(),
|
||||
'moderation_note' => $validated['moderation_note'] ?? null,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Comment approved successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject a comment.
|
||||
*/
|
||||
public function reject(Request $request, Comment $comment)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'moderation_note' => ['nullable', 'string', 'max:500'],
|
||||
]);
|
||||
|
||||
$comment->update([
|
||||
'status' => 'rejected',
|
||||
'moderated_by' => auth()->id(),
|
||||
'moderated_at' => now(),
|
||||
'moderation_note' => $validated['moderation_note'] ?? null,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Comment rejected successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set comment back to pending status.
|
||||
*/
|
||||
public function setPending(Request $request, Comment $comment)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'moderation_note' => ['nullable', 'string', 'max:500'],
|
||||
]);
|
||||
|
||||
$comment->update([
|
||||
'status' => 'pending',
|
||||
'moderated_by' => auth()->id(),
|
||||
'moderated_at' => now(),
|
||||
'moderation_note' => $validated['moderation_note'] ?? null,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Comment status changed to pending review.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a comment.
|
||||
*/
|
||||
public function destroy(Comment $comment)
|
||||
{
|
||||
$comment->delete();
|
||||
|
||||
return redirect()->route('moderation.comments.index')
|
||||
->with('success', 'Comment deleted successfully.');
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,19 @@ class Comment extends Model
|
||||
'user_id',
|
||||
'product_id',
|
||||
'body',
|
||||
'status',
|
||||
'moderated_by',
|
||||
'moderated_at',
|
||||
'moderation_note',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'moderated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -33,4 +46,36 @@ class Comment extends Model
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the moderator who moderated the comment.
|
||||
*/
|
||||
public function moderator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'moderated_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if comment is pending moderation.
|
||||
*/
|
||||
public function isPending(): bool
|
||||
{
|
||||
return $this->status === 'pending';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if comment is approved.
|
||||
*/
|
||||
public function isApproved(): bool
|
||||
{
|
||||
return $this->status === 'approved';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if comment is rejected.
|
||||
*/
|
||||
public function isRejected(): bool
|
||||
{
|
||||
return $this->status === 'rejected';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('comments', function (Blueprint $table) {
|
||||
$table->string('status')->default('pending')->after('body'); // pending, approved, rejected
|
||||
$table->foreignId('moderated_by')->nullable()->after('status')->constrained('users')->nullOnDelete();
|
||||
$table->timestamp('moderated_at')->nullable()->after('moderated_by');
|
||||
$table->text('moderation_note')->nullable()->after('moderated_at');
|
||||
|
||||
$table->index('status');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('comments', function (Blueprint $table) {
|
||||
$table->dropForeign(['moderated_by']);
|
||||
$table->dropColumn(['status', 'moderated_by', 'moderated_at', 'moderation_note']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -164,6 +164,16 @@
|
||||
Manage Categories
|
||||
</div>
|
||||
</a>
|
||||
<a href="{{ route('moderation.comments.index') }}"
|
||||
class="block px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700"
|
||||
>
|
||||
<div class="flex items-center">
|
||||
<svg class="mr-2 h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"></path>
|
||||
</svg>
|
||||
Moderate Comments
|
||||
</div>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
<form method="POST" action="{{ route('logout') }}">
|
||||
@@ -234,6 +244,10 @@
|
||||
class="block pl-3 pr-4 py-2 border-l-4 text-base font-medium {{ request()->routeIs('categories.*') ? 'border-primary-500 text-primary-700 bg-primary-50 dark:bg-primary-900 dark:text-primary-200' : 'border-transparent text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-700 hover:border-gray-300 dark:hover:border-gray-600 hover:text-gray-700 dark:hover:text-gray-300' }}">
|
||||
Manage Categories
|
||||
</a>
|
||||
<a href="{{ route('moderation.comments.index') }}"
|
||||
class="block pl-3 pr-4 py-2 border-l-4 text-base font-medium {{ request()->routeIs('moderation.comments.*') ? 'border-primary-500 text-primary-700 bg-primary-50 dark:bg-primary-900 dark:text-primary-200' : 'border-transparent text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-700 hover:border-gray-300 dark:hover:border-gray-600 hover:text-gray-700 dark:hover:text-gray-300' }}">
|
||||
Moderate Comments
|
||||
</a>
|
||||
@endif
|
||||
@endauth
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="bg-gray-50 dark:bg-gray-900 min-h-screen">
|
||||
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
<!-- Header -->
|
||||
<div class="mb-8">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-gray-900 dark:text-white">Edit Comment</h1>
|
||||
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Modify comment content</p>
|
||||
</div>
|
||||
<a
|
||||
href="{{ route('moderation.comments.index') }}"
|
||||
class="px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-md font-medium transition-colors"
|
||||
>
|
||||
Back to Comments
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Comment Info -->
|
||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6 mb-6">
|
||||
<h3 class="text-sm font-medium text-gray-900 dark:text-white mb-4">Comment Information</h3>
|
||||
<div class="grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<span class="text-gray-500 dark:text-gray-400">Author:</span>
|
||||
<a href="{{ route('profile.show', $comment->user) }}" class="ml-2 text-primary-600 dark:text-primary-400 hover:underline">
|
||||
{{ $comment->user->name }}
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500 dark:text-gray-400">Product:</span>
|
||||
<a href="{{ route('products.show', $comment->product) }}" class="ml-2 text-primary-600 dark:text-primary-400 hover:underline">
|
||||
{{ $comment->product->name }}
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500 dark:text-gray-400">Posted:</span>
|
||||
<span class="ml-2 text-gray-900 dark:text-white">{{ $comment->created_at->format('M d, Y h:i A') }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500 dark:text-gray-400">Status:</span>
|
||||
@if($comment->isPending())
|
||||
<span class="ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-yellow-100 dark:bg-yellow-900 text-yellow-800 dark:text-yellow-200">
|
||||
Pending
|
||||
</span>
|
||||
@elseif($comment->isApproved())
|
||||
<span class="ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200">
|
||||
Approved
|
||||
</span>
|
||||
@else
|
||||
<span class="ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 dark:bg-red-900 text-red-800 dark:text-red-200">
|
||||
Rejected
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if($comment->moderated_at)
|
||||
<div class="mt-4 pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||
<div class="text-xs text-gray-600 dark:text-gray-400">
|
||||
<strong>Moderated by:</strong> {{ $comment->moderator->name ?? 'Unknown' }}
|
||||
<span class="mx-2">•</span>
|
||||
<strong>Date:</strong> {{ $comment->moderated_at->format('M d, Y h:i A') }}
|
||||
</div>
|
||||
@if($comment->moderation_note)
|
||||
<div class="text-xs text-gray-600 dark:text-gray-400 mt-1">
|
||||
<strong>Note:</strong> {{ $comment->moderation_note }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<!-- Edit Form -->
|
||||
<form action="{{ route('moderation.comments.update', $comment) }}" method="POST" class="space-y-6">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6">
|
||||
<div>
|
||||
<label for="body" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Comment Content <span class="text-red-500">*</span>
|
||||
</label>
|
||||
<textarea
|
||||
name="body"
|
||||
id="body"
|
||||
rows="6"
|
||||
required
|
||||
class="w-full rounded-md border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm focus:border-primary-500 focus:ring-primary-500 @error('body') border-red-500 @enderror"
|
||||
>{{ old('body', $comment->body) }}</textarea>
|
||||
@error('body')
|
||||
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="mt-1 text-sm text-gray-500 dark:text-gray-400">
|
||||
Edit the comment content if needed (max 1000 characters)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="flex items-center justify-between">
|
||||
<a
|
||||
href="{{ route('moderation.comments.index') }}"
|
||||
class="px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-md font-medium transition-colors"
|
||||
>
|
||||
Cancel
|
||||
</a>
|
||||
<button
|
||||
type="submit"
|
||||
class="px-6 py-2 bg-primary-600 hover:bg-primary-700 text-white rounded-md font-medium transition-colors"
|
||||
>
|
||||
Update Comment
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Moderation Actions -->
|
||||
<div class="mt-6 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6">
|
||||
<h3 class="text-sm font-medium text-gray-900 dark:text-white mb-4">Change Comment Status</h3>
|
||||
|
||||
@if($comment->isPending())
|
||||
<div class="flex gap-3">
|
||||
<form action="{{ route('moderation.comments.approve', $comment) }}" method="POST" class="flex-1">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full inline-flex items-center justify-center px-4 py-2 bg-green-600 hover:bg-green-700 text-white rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-5 w-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
|
||||
</svg>
|
||||
Approve Comment
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<form action="{{ route('moderation.comments.reject', $comment) }}" method="POST" class="flex-1">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full inline-flex items-center justify-center px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-5 w-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
Reject Comment
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
@elseif($comment->isApproved())
|
||||
<div class="flex gap-3">
|
||||
<form action="{{ route('moderation.comments.setPending', $comment) }}" method="POST" class="flex-1">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full inline-flex items-center justify-center px-4 py-2 bg-yellow-600 hover:bg-yellow-700 text-white rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-5 w-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
Set to Pending
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<form action="{{ route('moderation.comments.reject', $comment) }}" method="POST" class="flex-1">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full inline-flex items-center justify-center px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-5 w-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
Reject Comment
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
@else
|
||||
<div class="flex gap-3">
|
||||
<form action="{{ route('moderation.comments.setPending', $comment) }}" method="POST" class="flex-1">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full inline-flex items-center justify-center px-4 py-2 bg-yellow-600 hover:bg-yellow-700 text-white rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-5 w-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
Set to Pending
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<form action="{{ route('moderation.comments.approve', $comment) }}" method="POST" class="flex-1">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full inline-flex items-center justify-center px-4 py-2 bg-green-600 hover:bg-green-700 text-white rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-5 w-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
|
||||
</svg>
|
||||
Approve Comment
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -0,0 +1,292 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="bg-gray-50 dark:bg-gray-900 min-h-screen">
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
<!-- Header -->
|
||||
<div class="mb-8">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-gray-900 dark:text-white">Comment Moderation</h1>
|
||||
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Review and moderate user comments</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Success/Error Messages -->
|
||||
@if(session('success'))
|
||||
<div class="mb-6 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 text-green-800 dark:text-green-200 px-4 py-3 rounded-lg">
|
||||
{{ session('success') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if(session('error'))
|
||||
<div class="mb-6 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-red-800 dark:text-red-200 px-4 py-3 rounded-lg">
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- Tabs and Search -->
|
||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 mb-6">
|
||||
<!-- Status Tabs -->
|
||||
<div class="border-b border-gray-200 dark:border-gray-700">
|
||||
<nav class="flex -mb-px">
|
||||
<a href="{{ route('moderation.comments.index', ['status' => 'pending']) }}"
|
||||
class="px-6 py-3 text-sm font-medium border-b-2 {{ request('status', 'pending') === 'pending' ? 'border-primary-500 text-primary-600 dark:text-primary-400' : 'border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 hover:border-gray-300' }}">
|
||||
Pending
|
||||
@if($pendingCount > 0)
|
||||
<span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 dark:bg-yellow-900 text-yellow-800 dark:text-yellow-200">
|
||||
{{ $pendingCount }}
|
||||
</span>
|
||||
@endif
|
||||
</a>
|
||||
<a href="{{ route('moderation.comments.index', ['status' => 'approved']) }}"
|
||||
class="px-6 py-3 text-sm font-medium border-b-2 {{ request('status') === 'approved' ? 'border-primary-500 text-primary-600 dark:text-primary-400' : 'border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 hover:border-gray-300' }}">
|
||||
Approved ({{ $approvedCount }})
|
||||
</a>
|
||||
<a href="{{ route('moderation.comments.index', ['status' => 'rejected']) }}"
|
||||
class="px-6 py-3 text-sm font-medium border-b-2 {{ request('status') === 'rejected' ? 'border-primary-500 text-primary-600 dark:text-primary-400' : 'border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 hover:border-gray-300' }}">
|
||||
Rejected ({{ $rejectedCount }})
|
||||
</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<!-- Search -->
|
||||
<div class="p-4">
|
||||
<form method="GET" action="{{ route('moderation.comments.index') }}" class="flex gap-4">
|
||||
<input type="hidden" name="status" value="{{ request('status', 'pending') }}">
|
||||
<div class="flex-1">
|
||||
<input
|
||||
type="text"
|
||||
name="search"
|
||||
value="{{ request('search') }}"
|
||||
placeholder="Search comments, users, or products..."
|
||||
class="w-full rounded-md border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm focus:border-primary-500 focus:ring-primary-500"
|
||||
>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
class="px-4 py-2 bg-primary-600 hover:bg-primary-700 text-white rounded-md font-medium transition-colors"
|
||||
>
|
||||
Search
|
||||
</button>
|
||||
@if(request('search'))
|
||||
<a
|
||||
href="{{ route('moderation.comments.index', ['status' => request('status', 'pending')]) }}"
|
||||
class="px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-md font-medium transition-colors"
|
||||
>
|
||||
Clear
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Comments List -->
|
||||
<div class="space-y-4">
|
||||
@forelse($comments as $comment)
|
||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 overflow-hidden">
|
||||
<div class="p-6">
|
||||
<!-- Comment Header -->
|
||||
<div class="flex items-start justify-between mb-4">
|
||||
<div class="flex items-start space-x-4">
|
||||
<div class="h-10 w-10 rounded-full bg-gradient-to-br from-primary-500 to-accent-500 flex items-center justify-center text-white font-semibold">
|
||||
{{ strtoupper(substr($comment->user->name, 0, 1)) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="flex items-center gap-2">
|
||||
<a href="{{ route('profile.show', $comment->user) }}" class="text-sm font-medium text-gray-900 dark:text-white hover:text-primary-600 dark:hover:text-primary-400">
|
||||
{{ $comment->user->name }}
|
||||
</a>
|
||||
<span class="text-xs text-gray-500 dark:text-gray-400">•</span>
|
||||
<span class="text-xs text-gray-500 dark:text-gray-400">
|
||||
{{ $comment->created_at->diffForHumans() }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">
|
||||
On product: <a href="{{ route('products.show', $comment->product) }}" class="text-primary-600 dark:text-primary-400 hover:underline">{{ $comment->product->name }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Status Badge -->
|
||||
<div>
|
||||
@if($comment->isPending())
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 dark:bg-yellow-900 text-yellow-800 dark:text-yellow-200">
|
||||
Pending Review
|
||||
</span>
|
||||
@elseif($comment->isApproved())
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200">
|
||||
Approved
|
||||
</span>
|
||||
@else
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 dark:bg-red-900 text-red-800 dark:text-red-200">
|
||||
Rejected
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Comment Body -->
|
||||
<div class="mb-4">
|
||||
<p class="text-gray-700 dark:text-gray-300 whitespace-pre-wrap">{{ $comment->body }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Moderation Info -->
|
||||
@if($comment->moderated_at)
|
||||
<div class="mb-4 bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-md p-3">
|
||||
<div class="text-xs text-gray-600 dark:text-gray-400">
|
||||
<strong>Moderated by:</strong> {{ $comment->moderator->name ?? 'Unknown' }}
|
||||
<span class="mx-2">•</span>
|
||||
<strong>Date:</strong> {{ $comment->moderated_at->format('M d, Y h:i A') }}
|
||||
</div>
|
||||
@if($comment->moderation_note)
|
||||
<div class="text-xs text-gray-600 dark:text-gray-400 mt-1">
|
||||
<strong>Note:</strong> {{ $comment->moderation_note }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="flex items-center gap-2 pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||
@if($comment->isPending())
|
||||
<!-- Approve -->
|
||||
<form action="{{ route('moderation.comments.approve', $comment) }}" method="POST" class="inline">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="inline-flex items-center px-3 py-1.5 bg-green-600 hover:bg-green-700 text-white text-sm rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
|
||||
</svg>
|
||||
Approve
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- Reject -->
|
||||
<form action="{{ route('moderation.comments.reject', $comment) }}" method="POST" class="inline">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="inline-flex items-center px-3 py-1.5 bg-red-600 hover:bg-red-700 text-white text-sm rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
Reject
|
||||
</button>
|
||||
</form>
|
||||
@elseif($comment->isApproved())
|
||||
<!-- Set to Pending -->
|
||||
<form action="{{ route('moderation.comments.setPending', $comment) }}" method="POST" class="inline">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="inline-flex items-center px-3 py-1.5 bg-yellow-600 hover:bg-yellow-700 text-white text-sm rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
Set to Pending
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- Reject -->
|
||||
<form action="{{ route('moderation.comments.reject', $comment) }}" method="POST" class="inline">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="inline-flex items-center px-3 py-1.5 bg-red-600 hover:bg-red-700 text-white text-sm rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
Reject
|
||||
</button>
|
||||
</form>
|
||||
@else
|
||||
<!-- Set to Pending -->
|
||||
<form action="{{ route('moderation.comments.setPending', $comment) }}" method="POST" class="inline">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="inline-flex items-center px-3 py-1.5 bg-yellow-600 hover:bg-yellow-700 text-white text-sm rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
Set to Pending
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- Approve -->
|
||||
<form action="{{ route('moderation.comments.approve', $comment) }}" method="POST" class="inline">
|
||||
@csrf
|
||||
<button
|
||||
type="submit"
|
||||
class="inline-flex items-center px-3 py-1.5 bg-green-600 hover:bg-green-700 text-white text-sm rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
|
||||
</svg>
|
||||
Approve
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
<!-- Edit -->
|
||||
<a
|
||||
href="{{ route('moderation.comments.edit', $comment) }}"
|
||||
class="inline-flex items-center px-3 py-1.5 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 text-sm rounded-md font-medium transition-colors"
|
||||
>
|
||||
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
|
||||
</svg>
|
||||
Edit
|
||||
</a>
|
||||
|
||||
<!-- Delete -->
|
||||
<form
|
||||
action="{{ route('moderation.comments.destroy', $comment) }}"
|
||||
method="POST"
|
||||
onsubmit="return confirm('Are you sure you want to delete this comment?');"
|
||||
class="inline"
|
||||
>
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button
|
||||
type="submit"
|
||||
class="inline-flex items-center px-3 py-1.5 text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 text-sm font-medium"
|
||||
>
|
||||
<svg class="h-4 w-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
|
||||
</svg>
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-12 text-center">
|
||||
<svg class="h-12 w-12 text-gray-400 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"></path>
|
||||
</svg>
|
||||
<p class="text-sm text-gray-500 dark:text-gray-400">No comments found</p>
|
||||
</div>
|
||||
@endforelse
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
@if($comments->hasPages())
|
||||
<div class="mt-6">
|
||||
{{ $comments->links() }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -6,6 +6,7 @@ use App\Http\Controllers\AdminController;
|
||||
use App\Http\Controllers\BookmarkController;
|
||||
use App\Http\Controllers\CategoryManagementController;
|
||||
use App\Http\Controllers\CommentController;
|
||||
use App\Http\Controllers\CommentModerationController;
|
||||
use App\Http\Controllers\ProductController;
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use App\Http\Controllers\UpvoteController;
|
||||
@@ -63,6 +64,17 @@ Route::middleware(['auth', 'moderator'])->group(function () {
|
||||
|
||||
// Category Management Routes (Moderators & Admins)
|
||||
Route::resource('categories', CategoryManagementController::class);
|
||||
|
||||
// Comment Moderation Routes (Moderators & Admins)
|
||||
Route::prefix('moderation')->name('moderation.')->group(function () {
|
||||
Route::get('/comments', [CommentModerationController::class, 'index'])->name('comments.index');
|
||||
Route::get('/comments/{comment}/edit', [CommentModerationController::class, 'edit'])->name('comments.edit');
|
||||
Route::put('/comments/{comment}', [CommentModerationController::class, 'update'])->name('comments.update');
|
||||
Route::post('/comments/{comment}/approve', [CommentModerationController::class, 'approve'])->name('comments.approve');
|
||||
Route::post('/comments/{comment}/reject', [CommentModerationController::class, 'reject'])->name('comments.reject');
|
||||
Route::post('/comments/{comment}/pending', [CommentModerationController::class, 'setPending'])->name('comments.setPending');
|
||||
Route::delete('/comments/{comment}', [CommentModerationController::class, 'destroy'])->name('comments.destroy');
|
||||
});
|
||||
});
|
||||
|
||||
// Admin Routes
|
||||
|
||||
Reference in New Issue
Block a user