File: /var/www/vaspayment.com/app/Http/Controllers/CommentController.php
<?php
namespace App\Http\Controllers;
use App\Models\Comment;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
class CommentController extends Controller
{
public function __construct()
{
$this->middleware(['auth', 'verified']);
}
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'message' => [
'required',
'string',
'max:255',
function ($attribute, $value, $fail) {
$blacklist = [
'rubbish',
'hate',
'offensive',
'fool',
'stupid', // offensive words
'scam',
'fraud',
'phishing',
'spam',
'malware', // harmful content terms
'fake',
'cheat',
'hack',
'cyberattack',
'identity theft', // fraud and cyber-related words
'loan',
'invest',
'get rich',
'offer',
'money-back', // typical scam baiting terms
'earn quick money',
'click here',
'buy followers', // common scam-related phrases
'virus',
'trojan',
'spyware',
'keylogger',
'botnet', // malware-related terms
'killing', // malware-related terms
];
foreach ($blacklist as $word) {
if (stripos($value, $word) !== false) {
$fail('The ' . $attribute . ' field contains abusive or harmful content.');
}
}
},
],
]);
if ($validator->fails()) {
return redirect()->back()->with('error', $validator->errors()->first());
}
$comment = new Comment();
$comment->message = $request->get('message');
$comment->blog_id = $request->get('blog_id');
$comment->user_id = Auth::user()->id;
$comment->save();
return redirect()->back()->with('status', 'Comment Saved');
}
public function index()
{
$comments = Comment::orderBy("created_at", "desc")->paginate(10);
return view("settings.comment.index", compact("comments"));
}
public function create()
{
//
}
/**
* Display the specified resource.
*/
public function show(Comment $comment)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Comment $comment)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Comment $comment)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Comment $comment)
{
$comment->delete();
return redirect()->back()->with('status', 'Deleted Successfully');
}
}