nickurt/laravel-akismet
最新稳定版本:2.2.0
Composer 安装命令:
composer require nickurt/laravel-akismet
包简介
Akismet for Laravel 11.x & 12.x
README 文档
README
Installation
Install this package with composer:
composer require nickurt/laravel-akismet
Copy the config files for the api
php artisan vendor:publish --provider="nickurt\Akismet\ServiceProvider" --tag="config"
Configuration
The Akismet information can be set with environment values in the .env file (or directly in the config/akismet.php file)
AKISMET_APIKEY=MY_UNIQUE_APIKEY
AKISMET_BLOGURL=https://my-custom-blogurl.dev
Examples
Validation Rule
You can use a hidden-field akismet in your Form-Request to validate if the request is valid
// FormRequest ... public function rules() { return [ 'akismet' => [new \nickurt\Akismet\Rules\AkismetRule( request()->input('email'), request()->input('name') )] ]; } // Manually ... $validator = validator()->make(['akismet' => 'akismet'], ['akismet' => [new \nickurt\Akismet\Rules\AkismetRule( request()->input('email'), request()->input('name') )]]);
The AkismetRule requires a email and name parameter to validate the request.
Events
You can listen to the IsSpam, ReportSpam and ReportHam events, e.g. if you want to log all the IsSpam-requests in your application
IsSpam Event
This event will be fired when the request contains spam
nickurt\Akismet\Events\IsSpam
ReportSpam Event
This event will be fired when you succesfully reported spam
nickurt\Akismet\Events\ReportSpam
ReportHam Event
This event will be fired when you succesfully reported ham
nickurt\Akismet\Events\ReportHam
Custom Implementation
Validate Key
if( \Akismet::validateKey() ) { // valid } else { // invalid }
Set CommentAuthor Information
\Akismet::setCommentAuthor("John Doe") ->setCommentAuthorUrl("https://www.google.com") ->setCommentContent("It's me, John!") ->setCommentType('registration'); // etc // or \Akismet::fill([ 'comment_author' => 'John Doe', 'comment_author_url' => 'https://www.google.com', 'comment_content' => 'It's me, John!' ]); // etc
Is it Spam?
if( \Akismet::isSpam() ) { // yes, i'm spam! }
Submit Spam (missed spam)
if( \Akismet::reportSpam() ) { // yes, thanks! }
Submit Ham (false positives)
if( \Akismet::reportHam() ) { // yes, thanks! }
Tests
composer test
统计信息
- 总下载量: 129.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 98
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-27