Create single record from HasMany relationship in infolist actions

Hey, I'm trying to figure a way to show an action to create a single record in a HasMany relationship within an infolist page with SpatieMediaLibraryFileUpload field I tried multiple things but couldn't figure how to I have a model Project that has a HasMany relation on ProjectVersion, the ProjectVersion model is only there to host versioned files. Then I have a resource ProjectResource with an infolist ViewProject. On this page I have a tab that is dedicated to project versions and I'd like to be able to have an action that can add a new one into the list. Problem with infolist actions is that it registers the spatie medias to the main record, not the relation, only workaround I found is to add a repeater with all versions but I'd like to only have the "empty" new field in the add button. Thx for any help!
1 Reply
skyrowl
skyrowlOP2mo ago
if I can add anything to this, I'd like to do something like the following knowing that the main record is Project: (infolist component)
Actions::make([
Actions\Action::make('create-version')
->form([
SpatieMediaLibraryFileUpload::make('test')
->model(new ProjectVersion(['project_id' => $infolist->getRecord()->id]))
])
->action(function (array $data, Project $project, Form $form) {
$form->saveRelationships();
})
]),
Actions::make([
Actions\Action::make('create-version')
->form([
SpatieMediaLibraryFileUpload::make('test')
->model(new ProjectVersion(['project_id' => $infolist->getRecord()->id]))
])
->action(function (array $data, Project $project, Form $form) {
$form->saveRelationships();
})
]),
Want results from more Discord servers?
Add your server