Files
besttechfrom.eu/app/Http/Controllers/CommentController.php
T
2026-02-06 15:13:20 +02:00

44 lines
1.0 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Comment;
use App\Models\Product;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
class CommentController extends Controller
{
/**
* Store a newly created comment.
*/
public function store(Request $request, Product $product): RedirectResponse
{
$validated = $request->validate([
'body' => 'required|string|max:1000',
]);
Comment::create([
'user_id' => Auth::id(),
'product_id' => $product->id,
'body' => $validated['body'],
]);
return back()->with('success', 'Comment posted successfully!');
}
/**
* Remove the specified comment.
*/
public function destroy(Comment $comment): RedirectResponse
{
Gate::authorize('delete-comment', $comment);
$comment->delete();
return back()->with('success', 'Comment deleted successfully!');
}
}