#How do I customize how $addAction works?

3 messages · Page 1 of 1 (latest)

lyric walrusBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

tired mesa
#

Btw why is it that $this->orderAction is not getting the current value of the state?

$this->reorderAction(function (array $state) {
            // Ordinal Sorting
            $ordinalCounter = 0;
            foreach ($state as $key => &$item) {
                $item['ordinal'] = $ordinalCounter;
                $ordinalCounter++;

                QuestionOption::where('uuid', $item['uuid'])
                    ->update([
                        'ordinal' => $item['ordinal'],
                    ]);
            }

            dd($state);
        });
#
Answers::make('options')
    ->label('Possible Answers')
    ->relationship('options')
    ->reorderable()
    ->hidden(
        fn(callable $get) = > !in_array($get('type'),
                                        [ 'single_choice', 'multiple_choice' ]))
    ->addAction(function(Forms\Components\Actions\Action $action) {
      dd("Add Action Triggered");
    })
    ->reorderAction(function(array $state) {
      dd("Reorder Action Triggered", $state);
      // Ordinal Sorting
      $ordinalCounter = 0;
      foreach ($state as $key = > &$item) {
        $item['ordinal'] = $ordinalCounter;
        $ordinalCounter++;

        QuestionOption::where('uuid', $item['uuid'])->update([
          'ordinal' = > $item['ordinal'],
        ]);
      }
    }),