1. Go to this page and download the library: Download mchev/banhammer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mchev / banhammer example snippets
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Mchev\Banhammer\Traits\Bannable;
class User extends Authenticatable
{
use Bannable;
}
use Mchev\Banhammer\IP;
IP::ban("8.8.8.8");
IP::ban(["8.8.8.8", "4.4.4.4"]);
// Ban IP with expiration date
IP::ban("8.8.8.8", [], now()->addMinutes(10));
// Full
IP::ban(
"8.8.8.8",
[
"MetaKey1" => "MetaValue1",
"MetaKey2" => "MetaValue2",
],
now()->addMinutes(10)
);
use Mchev\Banhammer\IP;
IP::unban("8.8.8.8");
IP::unban(["8.8.8.8", "4.4.4.4"]);
$ban->setMeta('username', 'Jane');
$ban->getMeta('username'); // Jane
$ban->hasMeta('username'); // boolean
$ban->forgetMeta('username');
IP::banned()->whereMeta('username', 'Jane')->get();
// OR
$users->bans()->whereMeta('username', 'Jane')->get();
// OR
$users->whereBansMeta('username', 'Jane')->get();
use Mchev\Banhammer\Banhammer;
Banhammer::unbanExpired();
use Mchev\Banhammer\Banhammer;
Banhammer::clear();
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Mchev\Banhammer\Models\Ban as BanhammerBan;
class Ban extends BanhammerBan
{
use HasUuids;
}