engagement system
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?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!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user