© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
5 replies
Wirkhof

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()
$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
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
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Using $record into beforeCreate() method
FilamentFFilament / ❓┊help
3y ago
Get current record
FilamentFFilament / ❓┊help
3y ago
Custom Page Table Method Edit Action passing Current Record
FilamentFFilament / ❓┊help
13mo ago
canAccess() method not working when added to Custom Page
FilamentFFilament / ❓┊help
3y ago