F
Filament14mo ago
NoxyArg

Action on a resource that creates another resource?

Hello !! Is it possible to create an action on a resource that creates another resource? For example, I have the invoice resorces page , I want to add a button that passes the invoice data to the resource Order page + some custom data. For now the only thing I could achieve is a redirect action to create a new order ->action(fn() => redirect()->route('filament.admin.resources.orders.create')), tnxx !!
No description
Solution:
I achieve what I wanted, directly inserting the data in the DB ->action(function($record) { DB::table('orders')->insert( array('client_id' => $record->client_id, 'obra' => 'TEST', 'description' => $record->invoice_number, 'article_id' => 2, 'created_by' => auth()->user()->id) );...
Jump to solution
3 Replies
NoxyArg
NoxyArgOP14mo ago
Thanks for the answer, I'm going to investigate, for now I was able to send the data through the url and by request insert it into the forms, there must be a way to directly create the record without this step In the InvoiceResource i create a action Tables\Actions\Action::make('OrderCreate') ->action(fn ($record) => redirect()->route('filament.admin.resources.orders.create',['invoice_number' => $record->invoice_number, 'client_id' => $record->client_id,'obra' => $record->obra])) And in the OrderResource Forms\Components\TextInput::make('obra') ->default(function(Request $request) { return $request->input('invoice_number'); }) With this I fill the field
Solution
NoxyArg
NoxyArg14mo ago
I achieve what I wanted, directly inserting the data in the DB ->action(function($record) { DB::table('orders')->insert( array('client_id' => $record->client_id, 'obra' => 'TEST', 'description' => $record->invoice_number, 'article_id' => 2, 'created_by' => auth()->user()->id) ); })
Want results from more Discord servers?
Add your server