Bulk action to Get Selected Material and Create New Order With These Materials

Hello, I created this bulk action to get material selected and pass to a new order: Tables\Actions\BulkAction::make('Create Order') ->action(function (Collection $records) { redirect(OrderResource::getUrl('create'), [$records]); }), This is my form where I have a repeater to prefill with the material collection, but I have no ideia how to do: public static function form(Form $form): Form { return $form ->schema([ TextInput::make('number') ->required() ->maxLength(32), TextInput::make('total_price') ->numeric(), Select::make('status') ->options([ 'new' => 'Novo', 'processing' => 'Processado', 'shipped' => 'Enviado', 'delivered' => 'Entregue', 'cancelled' => 'Cancelado', ]) ->required(), Repeater::make('items') ->relationship() ->schema([ Select::make('material_id') ->relationship('material', 'name') ->columnSpan([ 'md' => 3, ]) ->required(), TextInput::make('qty') ->columnSpan([ 'md' => 2, ]) ->required(), TextInput::make('unit_price') ->disabled() ->dehydrated() ->columnSpan([ 'md' => 3, ]) ->required(), ]) ->defaultItems(1) ->columnSpan('full') ]); }
Solution:
1. pass the records ids as coma separated in redirect ` $data['item_ids'] = $records ->pluck('id') ->implode(',');...
Jump to solution
2 Replies
Solution
Arif Hossain
Arif Hossain12mo ago
1. pass the records ids as coma separated in redirect $data['item_ids'] = $records ->pluck('id') ->implode(','); return redirect()->route('filament.app.resources.orders.create', $data); 2. in the CreateOrder resource page, overwrite method fillForm as like below protected function fillForm(): void { $itemIds = collect (request('item_ids'))->explode(',')->toArray(); // for filling repeater field 'items' $data['items'] = collect(request('item_ids')) ->explode(',') ->map( function ($itemId) { $item = ''; // format/load/prepare item with itemId return [ "material_id" => $item->material_id, "qty" => $item->qnt, "unit_price" => $item->unit_price ]; } )->toArray() $this->callHook('beforeFill'); $this->form->fill($data); $this->callHook('afterFill'); }
ismaeltj9
ismaeltj9OP12mo ago
Hello @Arif Hossain, I did it in another way, basically I created a order record in database, e itens that belongs to this order e open this order to the user see, but I aprecited your solution, that give me ideas for other problems, thank you!
Want results from more Discord servers?
Add your server