antonioribeiro / firewall

Firewall package for Laravel applications
BSD 3-Clause "New" or "Revised" License
1.39k stars 162 forks source link

Non-static method PragmaRX\Firewall\Firewall::remove() should not be called statically #163

Closed lYesterdaYl closed 4 years ago

lYesterdaYl commented 4 years ago

Using Laravel 5.7, properly installed the package. Run php artisan firewall:list works fine, but when I try this in the controller. Not working.

        Firewall::remove($token->ip_address);
        Firewall::whitelist($request->ip_address);

Non-static method PragmaRX\Firewall\Firewall::remove() should not be called statically.

Not sure how I should call this method. Help please.

romuva commented 4 years ago

Still having the same problem on Laravel 7 even after using: use PragmaRX\Firewall\Firewall;

Error code: Non-static method PragmaRX\Firewall\Firewall::isBlacklisted() should not be called statically

Full controller code:

<?php

namespace App\Http\Controllers;

use PragmaRX\Firewall\Firewall;

class BansController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $blacklisted = Firewall::isBlacklisted('10.0.0.3');
        dd($blacklisted);
    }
}
dominikzyla commented 3 years ago

Just add directory Facades in vendor/pragmarx/firewall/src/

add File Firewall.php

<?php

namespace PragmaRX\Firewall\Facades;

use Illuminate\Support\Facades\Facade;

class Firewall extends Facade
{
    /**
     * The IoC key accessor.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return 'firewall';
    }
}

this worked for me. Dont forget to add it to config/app.php 'Firewall' => PragmaRX\Firewall\Vendor\Laravel\Facade::class, PragmaRX\Firewall\Vendor\Laravel\ServiceProvider::class,