method Illuminate\Auth\Access\Gate::allows() cannot be called statically

Viewed 64

I got this error when I wanted to use allows() method for Gate in my controller.

method Illuminate\Auth\Access\Gate::allows() cannot be called statically

public function boot()
{
    $this->registerPolicies();

    Gate::define('edit_product',function($user,$product){
        return $user->id === $product->user_id;
    });
}

Controller

class ProductController extends AdminController
{
    public function edit(Product $product)
    {
        if (Gate::allows('edit_product', $product)) {
            return view('admin.product.edit', compact('product'));
        } else {
            return "You haven't access to edit this product";
        }
    }
}

And my mistake was that I have use Illuminate\Auth\Access\Gate; instead Illuminate\Support\Facades\Gate;

0 Answers
Related