53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\User;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\User\StoreCommentRequest;
|
|
use App\Models\ProjectComment;
|
|
use App\Models\TranscriptionProject;
|
|
use App\Services\AuditLogService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
class CommentController extends Controller
|
|
{
|
|
public function store(
|
|
StoreCommentRequest $request,
|
|
TranscriptionProject $project,
|
|
AuditLogService $audit
|
|
): RedirectResponse {
|
|
$this->authorize('create', [ProjectComment::class, $project]);
|
|
|
|
$comment = $project->comments()->create([
|
|
'user_id' => auth()->id(),
|
|
'message' => $request->message,
|
|
]);
|
|
|
|
$audit->log('comment_added', [
|
|
'project_id' => $project->id,
|
|
'new_values' => ['comment_id' => $comment->id],
|
|
]);
|
|
|
|
return back()->with('success', 'Komen berjaya ditambah.');
|
|
}
|
|
|
|
public function destroy(
|
|
TranscriptionProject $project,
|
|
ProjectComment $comment,
|
|
AuditLogService $audit
|
|
): RedirectResponse {
|
|
abort_if($comment->project_id !== $project->id, 404);
|
|
|
|
$this->authorize('delete', $comment);
|
|
|
|
$audit->log('comment_deleted', [
|
|
'project_id' => $project->id,
|
|
'old_values' => ['comment_id' => $comment->id],
|
|
]);
|
|
|
|
$comment->delete();
|
|
|
|
return back()->with('success', 'Komen berjaya dipadam.');
|
|
}
|
|
}
|