How to create a resource record from another resource?

Hello, I'm creating a Booklet record from a modal in my Customer resource. The record is being saved, but I'm not getting the created notification. How can I properly create the record this way? This is my action button in my customers table:
Action::make('New Booklet')
->icon('heroicon-m-plus')
->form([
TextInput::make('customer_id')
->default(fn(Customer $customer) => $customer->code)
->readOnly(true),
Select::make('store_id')
->options(Store::all()->pluck('name', 'id'))
->required()
->native(false)
])
->action(function (array $data): void {
Booklet::create([
'customer_id' => $data['customer_id'],
'store_id' => $data['store_id'],
'user_id' => Filament::auth()->id(),
]);
}),
Action::make('New Booklet')
->icon('heroicon-m-plus')
->form([
TextInput::make('customer_id')
->default(fn(Customer $customer) => $customer->code)
->readOnly(true),
Select::make('store_id')
->options(Store::all()->pluck('name', 'id'))
->required()
->native(false)
])
->action(function (array $data): void {
Booklet::create([
'customer_id' => $data['customer_id'],
'store_id' => $data['store_id'],
'user_id' => Filament::auth()->id(),
]);
}),
3 Replies
Miyatake
MiyatakeOP11mo ago
Summarizing, what I'm trying to do is create a CreateAction for the Booklet model, but inside the CustomerResource table. Is it possible to bring the BookletResource form into the modal?
Alvaro Leon
Alvaro Leon11mo ago
You can use a relation manager (https://filamentphp.com/docs/3.x/panels/resources/relation-managers) for a UXed solution, or you can use the method after() into the Action to trigger the Notification.
Miyatake
MiyatakeOP11mo ago
Couldn't create the Booklet into the modal using the relation manager, but worked like a charm in the Customer edit page. Thank you, sir!
Want results from more Discord servers?
Add your server