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;
}
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;
}
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
Jump to solution
2 Replies
Wirkhof
WirkhofOP8mo ago
When I do this:
public static function canAccess(array $parameters = []): bool
{
dd($this->getRecord());
//return auth()->user()->id == 42;
}
public static function canAccess(array $parameters = []): bool
{
dd($this->getRecord());
//return auth()->user()->id == 42;
}
I will get:
Using $this when not in object context
Using $this when not in object context
How to get the record info inside the canAccess() function?
Solution
Ozumat77
Ozumat778mo ago
In the array $parameters, you already have the record
Want results from more Discord servers?
Add your server