Action button for creating relation on view page
I'm trying to duplicate the CreateAction button that is created with a RelationManager so that I can add it to the top of a ViewRecord page.
I got myself most of the way there with associating a model and reusing the Resource form but I'm not sure how to pass the record of the ViewRecord page to the form and also hide the select element in the form that pertains to the record being viewed.
Solution:Jump to solution
In my case, that doesn't work because I'm not in the context of a form or resource.
Filament\Resources\Pages\ViewRecord
is being passed through and doesn't have an $ownerRecord property.
However, that led to me searching through methods on the ViewRecord page and I found the ->getRecord()
method which gets the model for me and can be used in the current context.
Working code for my situation is here:...3 Replies
I got a little bit closer by filling in the form with static data but I can't seem to pull the record from the ViewRecord page.
would you like to get the owner record?
https://filamentphp.com/docs/3.x/panels/resources/relation-managers#accessing-the-relationships-owner-record
Solution
In my case, that doesn't work because I'm not in the context of a form or resource.
Filament\Resources\Pages\ViewRecord
is being passed through and doesn't have an $ownerRecord property.
However, that led to me searching through methods on the ViewRecord page and I found the ->getRecord()
method which gets the model for me and can be used in the current context.
Working code for my situation is here:
This will give me a button on the view page of a record where I can click to create a new relationship and prefill the ID (uuid) of the current resource.