Is it possible to pass the parent record to the gate of a relation manager?
I have a
Work Orders
resource and on the edit page of each is a relation manager for 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
method on the WorkOrderNotePolicy
that doesn't pass in anything other than the user. Eg.
Is there a way that I can pass in the parent/owner record to this method on the policy?Solution:Jump to solution
This is what I ended up doing on the relation manager. There are several
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.
```php
protected function canCreate(): bool
{...3 Replies
Another use case would be making sure noone can create a note on locked work orders.
Interesting, filament actually isn't checking a
create
method on the WorkOrderNotePolicy
but rather on the WorkOrderPolicy
. This is weird.Solution
This is what I ended up doing on the relation manager. There are several
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.
Yes, the
can
methods are probably the only way.