Miyatake
Miyatake
FFilament
Created by Miyatake on 1/10/2024 in #❓┊help
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(),
]);
}),
4 replies