© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•11mo ago•
5 replies
morty

Is it possible to pass the parent record to the gate of a relation manager?

I have a
Work Orders
Work Orders
resource and on the edit page of each is a relation manager for
Work Order Notes
Work Order Notes
. I have policies for both models.

I only want to allow a work order note to be created on work orders that the logged in user owns. The problem is that Filament checks a
create
create
method on the
WorkOrderNotePolicy
WorkOrderNotePolicy
that doesn't pass in anything other than the user. Eg.

class WorkOrderNotePolicy
{
    public function create(User $user): bool
    {
        //
    }
}
class WorkOrderNotePolicy
{
    public function create(User $user): bool
    {
        //
    }
}


Is there a way that I can pass in the parent/owner record to this method on the policy?
Solution
This is what I ended up doing on the relation manager. There are several
canAction
canAction
methods on the relation manager and I override the one's I need. Not sure if this is the best way to do this though but it works.

    protected function canCreate(): bool
    {
        return Gate::allows('create', [$this->getTable()->getModel(), $this->ownerRecord]);
    }
    protected function canCreate(): bool
    {
        return Gate::allows('create', [$this->getTable()->getModel(), $this->ownerRecord]);
    }
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

how to pass parent record to relation manager bulkaction
FilamentFFilament / ❓┊help
6mo ago
Access parent $record in relation manager
FilamentFFilament / ❓┊help
2y ago
Getting the attached and parent record in a relation manager hook
FilamentFFilament / ❓┊help
3y ago
Is it possible to add a Relation Manager in the subnavigation of a Resource?
FilamentFFilament / ❓┊help
2y ago