Create and Edit from RelationManager without modal

This is probably a question that might be answered somewhere, but I can't find it. I want to create and edit records from a relationmanager, without opening a modal. Just the normal create and edit pages. For both actions I need the parent record to be sent with it. Is this possible?
3 Replies
bwurtz999
bwurtz9999mo ago
Yes, it's possible. You would need to create a custom table action and then define a URL route - and it would take the user to the correct page
use Filament\Tables\Actions\Action;

//...

->actions([
Action::make('createResource')
->label('Create')
->button()
->url(function (RelationManager $livewire) {
return route('filament.admin.resources.other-resource.create') . '?resourceId=' . $livewire->ownerRecord->id;
}),
use Filament\Tables\Actions\Action;

//...

->actions([
Action::make('createResource')
->label('Create')
->button()
->url(function (RelationManager $livewire) {
return route('filament.admin.resources.other-resource.create') . '?resourceId=' . $livewire->ownerRecord->id;
}),
And then you would need to add a public variable on the Create page of the other resource with the same name as you define in the URL. And then it should automatically be applied to that variable
Saade
Saade9mo ago
@bwurtz999 is right, but the url generation is wrong, use:
// your relation manager
->url(
fn (RelationManager $livewire) => ChildResource::getUrl(name: 'create', parameters: ['parentId' => $livewire->ownerRecord->id])
)
// your relation manager
->url(
fn (RelationManager $livewire) => ChildResource::getUrl(name: 'create', parameters: ['parentId' => $livewire->ownerRecord->id])
)
// create page

use Livewire\Attributes\Url;

class CreateChild extends CreateRecord
{
#[Url(history: true, keep: true)]
public ?string $parentId = null;

public function mutateFormDataBeforeCreate(array $data): array
{
return [
...$data,
'parent_id' => $this->parentId,
];
}
}
// create page

use Livewire\Attributes\Url;

class CreateChild extends CreateRecord
{
#[Url(history: true, keep: true)]
public ?string $parentId = null;

public function mutateFormDataBeforeCreate(array $data): array
{
return [
...$data,
'parent_id' => $this->parentId,
];
}
}
Daniel Plomp
Daniel Plomp9mo ago
Thanks 🙏. I’ll give it a try