fix: update comment management
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\CommentUpdateRequest;
|
||||||
use App\Http\Requests\UpdateCommentRequest;
|
use App\Http\Requests\UpdateCommentRequest;
|
||||||
use App\Models\Comment;
|
use App\Models\Comment;
|
||||||
|
|
||||||
@@ -22,12 +23,12 @@ class CommentController extends Controller
|
|||||||
return view('admin.comments.show', compact('comment'));
|
return view('admin.comments.show', compact('comment'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(Comment $comment)
|
// public function edit(Comment $comment)
|
||||||
{
|
// {
|
||||||
return view('admin.comments.edit', compact('comment'));
|
// return view('admin.comments.edit', compact('comment'));
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function update(UpdateCommentRequest $request, Comment $comment)
|
public function update(CommentUpdateRequest $request, Comment $comment)
|
||||||
{
|
{
|
||||||
$comment->update($request->validated());
|
$comment->update($request->validated());
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ class CommentUpdateRequest extends FormRequest
|
|||||||
'body' =>
|
'body' =>
|
||||||
[
|
[
|
||||||
'required',
|
'required',
|
||||||
'string'
|
'string',
|
||||||
|
'min:3',
|
||||||
|
'max:1000'
|
||||||
],
|
],
|
||||||
'status' =>
|
'status' =>
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<div>
|
|
||||||
<!-- Very little is needed to make a happy life. - Marcus Aurelius -->
|
|
||||||
</div>
|
|
||||||
@@ -1,3 +1,82 @@
|
|||||||
<div>
|
@extends('admin.layouts.app')
|
||||||
<!-- Because you are alive, everything is possible. - Thich Nhat Hanh -->
|
|
||||||
</div>
|
@section('title', 'مدیریت نظرات')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="container-fluid py-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h4 class="mb-0">مدیریت نظرات</h4>
|
||||||
|
<span class="badge text-bg-primary">{{ $comments->total() }} نظر</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (session('success'))
|
||||||
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||||
|
{{ session('success') }}
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="بستن"></button>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover align-middle mb-0">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>کاربر</th>
|
||||||
|
<th>مرتبط با</th>
|
||||||
|
<th>متن نظر</th>
|
||||||
|
<th>وضعیت</th>
|
||||||
|
<th>تاریخ</th>
|
||||||
|
<th class="text-center">عملیات</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@forelse ($comments as $comment)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $comments->firstItem() + $loop->index }}</td>
|
||||||
|
<td>{{ $comment->user?->name ?? 'کاربر حذفشده' }}</td>
|
||||||
|
<td>
|
||||||
|
<span
|
||||||
|
class="d-block text-muted small">{{ class_basename($comment->commentable_type) }}</span>
|
||||||
|
<span class="small">شناسه: {{ $comment->commentable_id }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="text-truncate" style="max-width: 250px;">
|
||||||
|
{{ \Illuminate\Support\Str::limit($comment->body, 60) }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@include('admin.comments.status', ['status' => $comment->status])
|
||||||
|
</td>
|
||||||
|
<td class="small text-muted">{{ $comment->created_at->format('Y/m/d') }}</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<div class="btn-group btn-group-sm" role="group">
|
||||||
|
<a href="{{ route('admin.comments.show', $comment) }}"
|
||||||
|
class="btn btn-outline-secondary" title="نمایش">نمایش</a>
|
||||||
|
<a href="{{ route('admin.comments.edit', $comment) }}"
|
||||||
|
class="btn btn-outline-primary" title="ویرایش">ویرایش</a>
|
||||||
|
<form action="{{ route('admin.comments.destroy', $comment) }}" method="POST"
|
||||||
|
class="d-inline"
|
||||||
|
onsubmit="return confirm('نظر حذف شود؟')">
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<button type="submit" class="btn btn-outline-danger" title="حذف">حذف</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@empty
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="text-center text-muted py-4">هنوز نظری ثبت نشده است.</td>
|
||||||
|
</tr>
|
||||||
|
@endforelse
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-3">
|
||||||
|
{{ $comments->links() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,51 @@
|
|||||||
<div>
|
@extends('admin.layouts.app')
|
||||||
<!-- Knowing is not enough; we must apply. Being willing is not enough; we must do. - Leonardo da Vinci -->
|
|
||||||
</div>
|
@section('title', 'جزئیات نظر')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="container-fluid py-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h4 class="mb-0">جزئیات نظر #{{ $comment->id }}</h4>
|
||||||
|
<a href="{{ route('admin.comments.index') }}" class="btn btn-outline-secondary btn-sm">بازگشت</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-body">
|
||||||
|
<dl class="row mb-0">
|
||||||
|
<dt class="col-sm-3">کاربر</dt>
|
||||||
|
<dd class="col-sm-9">
|
||||||
|
{{ $comment->user?->name ?? 'کاربر حذفشده' }}
|
||||||
|
<span class="text-muted small">({{ $comment->user?->email ?? '—' }})</span>
|
||||||
|
</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">مرتبط با</dt>
|
||||||
|
<dd class="col-sm-9">
|
||||||
|
{{ class_basename($comment->commentable_type) }}
|
||||||
|
<span class="text-muted small">(شناسه: {{ $comment->commentable_id }})</span>
|
||||||
|
</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">وضعیت</dt>
|
||||||
|
<dd class="col-sm-9">@include('admin.comments.status', ['status' => $comment->status])</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">تاریخ ثبت</dt>
|
||||||
|
<dd class="col-sm-9">{{ $comment->created_at->format('Y/m/d H:i') }}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-3">متن نظر</dt>
|
||||||
|
<dd class="col-sm-9">
|
||||||
|
<div class="p-3 bg-light rounded" style="white-space: pre-wrap;">{{ $comment->body }}</div>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer bg-white">
|
||||||
|
<a href="{{ route('admin.comments.edit', $comment) }}" class="btn btn-primary btn-sm">ویرایش</a>
|
||||||
|
<form action="{{ route('admin.comments.destroy', $comment) }}" method="POST" class="d-inline"
|
||||||
|
onsubmit="return confirm('نظر حذف شود؟')">
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<button type="submit" class="btn btn-danger btn-sm">حذف</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user