F
Filamentβ€’3mo ago
setiawanh

Action button in View Resource to Show Create Popup based on Relationship Manager

I have an Employee resource with work_histories in relationship manager. I want to have an action button in the View Employee Resource which when click, will open the popup that is similar to the form for creating new work history in the relationship manager. What should I put in the URL / function when I create Action::make() ? Thanks!
Solution:
@setiawanh The URL for the resource of WorkHistoryResource would be WorkHistoryResource::getUrl('create') but as I understand you don't need the URL (and you may not even have a separate resource), you need to open the create form, so that is not the same, that wouldn't work. Can't you just show Relationship Manager in the View Employee Resource and it would contain that button?...
Jump to solution
4 Replies
Solution
Povilas K
Povilas Kβ€’3mo ago
@setiawanh The URL for the resource of WorkHistoryResource would be WorkHistoryResource::getUrl('create') but as I understand you don't need the URL (and you may not even have a separate resource), you need to open the create form, so that is not the same, that wouldn't work. Can't you just show Relationship Manager in the View Employee Resource and it would contain that button?
Jean Roumeau
Jean Roumeauβ€’3mo ago
I don't think you need the url() method. You could just add a Filament\Actions\CreateAction to the headerActions of the view page and load the form for the desired resource. Just remember to also add the model() method with the respective resource model class. I did something similiar but not sure if this suits you:
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
Actions\CreateAction::make()
->form(Organization::getForm())
->model(Organization::class),
];
}
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
Actions\CreateAction::make()
->form(Organization::getForm())
->model(Organization::class),
];
}
setiawanh
setiawanhβ€’3mo ago
@PovilasKorop thanks. In the end, I have tried to create a filament resource for EmployeeWorkHistory by itself and point the URL to there with prepopulated employee. Will see how this works πŸ™‚ Thanks! Thank you... getForm() as not found. What class is "Organization"?
Jean Roumeau
Jean Roumeauβ€’3mo ago
This is an example code I presented. Organization is one of my models which loads the form schema on the getForm() method. You should pass your own resource form schema and model.