How to bring current record into canAccess() method code?

I managed to restrict the access to the edit user page with this code:

public static function canAccess(array $parameters = []): bool
    {
        return auth()->user()->id == 42;
    }


and it works.

However, I need a bit more custom logic that uses some values from the record I am trying to access.

And I am unable to use $this->getRecord() inside the code like:

public static function canAccess(array $parameters = []): bool
    {
        $currentRecord = $this->getRecord();
        return auth()->user()->id == 42;
    }


I am getting this error:
Using $this when not in object context

Any idea how to access the record inside canAccess() method?
Solution
In the array $parameters, you already have the record
Was this page helpful?