Install this package with composer:
composer require nickurt/laravel-stopforumspam
Copy the config files for the StopForumSpam-plugin
php artisan vendor:publish --provider="nickurt\StopForumSpam\ServiceProvider" --tag="config"
// FormRequest ...
public function rules()
{
return [
'email' => ['required', new \nickurt\StopForumSpam\Rules\IsSpamEmail(20)]
];
}
// Manually ...
$validator = validator()->make(request()->all(), ['email' => ['required', new \nickurt\StopForumSpam\Rules\IsSpamEmail(20)]]);The IsSpamEmail-rule has one optional paramter frequency (default 10) to validate the request.
// FormRequest ...
public function rules()
{
return [
'ip' => ['required', new \nickurt\StopForumSpam\Rules\IsSpamIp(20)]
];
}
// Manually ...
$validator = validator()->make(request()->all(), ['ip' => ['required', new \nickurt\StopForumSpam\Rules\IsSpamIp(20)]]);The IsSpamIp-rule has one optional paramter frequency (default 10) to validate the request.
// FormRequest ...
public function rules()
{
return [
'username' => ['required', new \nickurt\StopForumSpam\Rules\IsSpamUsername(20)]
];
}
// Manually ...
$validator = validator()->make(request()->all(), ['username' => ['required', new \nickurt\StopForumSpam\Rules\IsSpamUsername(20)]]);The IsSpamUsername-rule has one optional paramter frequency (default 10) to validate the request.
\StopForumSpam::setEmail('nickurt@users.noreply.github.com')->isSpamEmail();\StopForumSpam::setIp('8.8.8.8')->isSpamIp();\StopForumSpam::setUsername('nickurt')->isSpamUsername();You can report a spammer to the StopForumSpam database using reportSpam(). This requires an API key (set STOPFORUMSPAM_APIKEY in your .env) and all three of: ip, email, and username. Evidence is optional and should be the post content. Do not include your email or site URL in Evidence.
See Adding to the Database for more information: https://www.stopforumspam.com/usage
\StopForumSpam::setIp('8.8.8.8')
->setEmail('spam@example.com')
->setUsername('spammer')
->reportSpam();
// Optionally include evidence
\StopForumSpam::setIp('8.8.8.8')
->setEmail('spam@example.com')
->setUsername('spammer')
->setEvidence('Posted 50 identical spam messages.')
->reportSpam();Returns true on success. Throws a MalformedIPException if the IP is invalid, a MalformedEmailException if the email is invalid, or an Exception if the API key or any required field is missing.
You can listen to the IsSpamEmail, IsSpamIp and IsSpamUsername events, e.g. if you want to log all the IsSpam-requests in your application
This event will be fired when the request-email is above the frequency of sending spam
nickurt\StopForumSpam\Events\IsSpamEmail
This event will be fired when the request-ip is above the frequency of sending spam
nickurt\StopForumSpam\Events\IsSpamIp
This event will be fired when the request-username is above the frequency of sending spam
nickurt\StopForumSpam\Events\IsSpamUsername
composer test