Skip to content

add item to table repeater #112

Answered by lpcs007
lpcs007 asked this question in Q&A
Apr 6, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Working now!

->action(function (array $data, \Awcodes\TableRepeater\Components\TableRepeater $component, \Filament\Forms\Components\Actions\Action $action, \Filament\Forms\Form $form): void {
    $product = Product::find($data['id']);

    $newUuid = $component->generateUuid();

    $items = $component->getState();

    foreach ($items as $uuid => $item) {
        if ($item['product_id'] === null) {
            unset($items[$uuid]);
        }

        if ($item['product_id'] == $product->id) {
            $items[$uuid]['quantity'] += 1;
            $updated = true;
        }
    }

    if(!isset($updated)){
        $items[$newUuid] = [
            'product_id' => $product->id,
            '…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@lpcs007
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by lpcs007
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants