update data in other tables
Please guide me for updating other tables without using repeater .
Ex. I want to update automatically the quantity of items after submitting the invoice in invoiceresource.
6 Replies
->actions([
Tables\Actions\Action::make('Qty')
->name('Quantity')
// ->iconButton()
->form([Forms\Components\TextInput::make('udpate_qty')
->name('')
->numeric()
])
// ->action(function (array $data): void{
// Item::updated([$data]);
// })
->action(function ($get, $state) {
DB::table('items')
->where('item_code',$get('item_code'))
->update(['item_qty'=> $get('item_qty')+ $state]);
})
->modalWidth('sm')
is this ok to use ?
Hi @yeonjih, check tip # 4 here on how to format your code:
https://discord.com/channels/883083792112300104/883264995603935272/983367389905305611
Do you have any issues with this? Is the code doing what you want?
I will try later. Thank you for response
Hello, my problem now is how to fetch from input text. I got an error if I use fn($get)=>get('field_name')
->actions([
Tables\Actions\Action::make('Qty')
->name('Quantity') // ->iconButton() ->form([Forms\Components\TextInput::make('update_qty') ->name('') ->numeric() ->required() ]) ->action(function($record){ Item::where('id',$record->id) ->update([ "item_qty" => //I need to post here ]); }) @pboivin Hello regarding this matter π thank you
->name('Quantity') // ->iconButton() ->form([Forms\Components\TextInput::make('update_qty') ->name('') ->numeric() ->required() ]) ->action(function($record){ Item::where('id',$record->id) ->update([ "item_qty" => //I need to post here ]); }) @pboivin Hello regarding this matter π thank you
Thank you. It works