2017 © Pedro Peláez
 

library akismet-spam

Akismet Service for spam detection.

image

chrisyoyo/akismet-spam

Akismet Service for spam detection.

  • Friday, November 25, 2016
  • by devchris
  • Repository
  • 1 Watchers
  • 1 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

About

Build Status, (*1)

Laravel 5 package that allows you to deal with spams using Akismet., (*2)

Usage

In your project: composer require chrisyoyo/akismet-spam, (*3)

In config/app.php providers:, (*4)

Chrisyoyo\AkismetSpam\SpamServiceProvider::class,

Next, publish the package default config:, (*5)

php artisan vendor:publish --provider="Chrisyoyo\AkismetSpam\SpamServiceProvider"

In the .env change your akismet secret and website., (*6)

Then add a boolean 'spam' column with default to false on models you want to use. And add the spammable trait, and the getSpamColumns function to it like this :, (*7)


<?php namespace App; use Illuminate\Database\Eloquent\Model; use Chrisyoyo\AkismetSpam\Spammable; class Post extends Model { use Spammable; public function getSpamColumns() { return [ 'body' => 'body', 'author' => 'user.name', 'author_email' => 'user.email', ]; } public function user() { return $this->belongsTo(User::class); } } ...

It is very flexible, in your controller you have 3 choices of implementation, first the easiest for the store method:, (*8)


public function store(Request $request) { $post = new Post; $post->body = 'Hello, my name is ' . $request->user()->name; $post->user()->associate($request->user()); if ($post->isSpam()) { $post->spam = true; } $post->save(); } ...

It can be done because you have the Spammable trait on your model., (*9)

You can also add the interface on your controller and use it like this:, (*10)


use Chrisyoyo\AkismetSpam\Service\SpamServiceInterface; ... protected $spam; public function __construct(SpamServiceInterface $spam) { $this->middleware(['auth']); $this->spam = $spam; } public function store(Request $request) { $post = new Post; $post->body = 'Hello, my name is ' . $request->user()->name; $post->user()->associate($request->user()); if ($this->spam->isSpam([ 'body' => $post->body, 'author' => $post->user->name, 'author_email' => $post->user->email, ])) { $this->spam->markAsSpam([ 'body' => $post->body, 'author' => $post->user->name, 'author_email' => $post->user->email, ]); $post->spam = true; } $post->save(); } ...

or simply use the Spam Facade:, (*11)


use Chrisyoyo\AkismetSpam\Spam; ... public function store(Request $request) { if (Spam::isSpam([ 'body' => $post->body, 'author' => $post->user->name, 'author_email' => $post->user->email, ])) { Spam::markAsSpam([ 'body' => $post->body, 'author' => $post->user->name, 'author_email' => $post->user->email, ]) $post->spam = true; } } ...

Then you have two examples function to mark as a spam, or say that is not a spam., (*12)

public function spam(Post $post)
{
    $post->markAsSpam();

    $post->spam = true;
    $post->save();
}

public function ham(Post $post)
{
    $post->markAsHam();

    $post->spam = false;
    $post->save();
}

...

The Versions

25/11 2016

dev-master

9999999-dev http://github.com/chrisyoyo/akismet-spam

Akismet Service for spam detection.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christopher Yovanovitch

laravel spam akismet

25/11 2016

1.1

1.1.0.0 http://github.com/chrisyoyo/akismet-spam

Akismet Service for spam detection.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christopher Yovanovitch

laravel spam akismet

25/11 2016

1.0

1.0.0.0 http://github.com/chrisyoyo/akismet-spam

Akismet Service for spam detection.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christopher Yovanovitch

laravel spam akismet