Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.5 kB
1
Indexable
Never
use App\Models\Comment;
use Illuminate\Http\Request;

class CommentController extends Controller
{
    public function store(Request $request)
    {
        // Validate request data
        $request->validate([
            'name' => 'required',
            'email' => 'required|email',
            'text' => 'required',
        ]);

        // Create new comment
        Comment::create($request->all());

        return redirect()->back()->with('success', 'Comment added successfully.');
    }

    public function update(Request $request, Comment $comment)
    {
        // Update comment
        $comment->update($request->all());

        return redirect()->back()->with('success', 'Comment updated successfully.');
    }

    public function destroy(Comment $comment)
    {
        // Delete comment
        $comment->delete();

        return redirect()->back()->with('success', 'Comment deleted successfully.');
    }
}





use App\Models\Comment;

class AdminController extends Controller
{
    public function index()
    {
        // Retrieve comments for admin approval
        $comments = Comment::where('approved', false)->get();
        return view('admin.comments.index', compact('comments'));
    }

    public function approveComment(Comment $comment)
    {
        // Approve the comment for publishing
        $comment->update(['approved' => true]);
        return redirect()->back()->with('success', 'Comment approved successfully.');
    }
}
Leave a Comment