项目作者: nickurt

项目描述 :
Akismet for Laravel 6.x/7.x/8.x
高级语言: PHP
项目地址: git://github.com/nickurt/laravel-akismet.git
创建时间: 2015-05-27T09:15:48Z
项目社区:https://github.com/nickurt/laravel-akismet

开源协议:MIT License

下载


Laravel Akismet

Build Status
Total Downloads
Latest Stable Version
MIT Licensed

Installation

Install this package with composer:

  1. composer require nickurt/laravel-akismet

Copy the config files for the api

  1. 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)

  1. AKISMET_APIKEY=MY_UNIQUE_APIKEY
  2. 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

  1. // FormRequest ...
  2. public function rules()
  3. {
  4. return [
  5. 'akismet' => [new \nickurt\Akismet\Rules\AkismetRule(
  6. request()->input('email'), request()->input('name')
  7. )]
  8. ];
  9. }
  10. // Manually ...
  11. $validator = validator()->make(['akismet' => 'akismet'], ['akismet' => [new \nickurt\Akismet\Rules\AkismetRule(
  12. request()->input('email'), request()->input('name')
  13. )]]);

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
  1. if( \Akismet::validateKey() ) {
  2. // valid
  3. } else {
  4. // invalid
  5. }
Set CommentAuthor Information
  1. \Akismet::setCommentAuthor("John Doe")
  2. ->setCommentAuthorUrl("https://www.google.com")
  3. ->setCommentContent("It's me, John!")
  4. ->setCommentType('registration');
  5. // etc
  6. // or
  7. \Akismet::fill([
  8. 'comment_author' => 'John Doe',
  9. 'comment_author_url' => 'https://www.google.com',
  10. 'comment_content' => 'It's me, John!'
  11. ]);
  12. // etc
Is it Spam?
  1. if( \Akismet::isSpam() ) {
  2. // yes, i'm spam!
  3. }
Submit Spam (missed spam)
  1. if( \Akismet::reportSpam() ) {
  2. // yes, thanks!
  3. }
Submit Ham (false positives)
  1. if( \Akismet::reportHam() ) {
  2. // yes, thanks!
  3. }

Tests

  1. composer test