0

I tried to append several values in the same column of Laravel AJAX datatable. Here is what I typed in the controller :

$table->addColumn('academic_options', function ($row) {
                return ($row->academic_section ? $row->academic_section->code : '') . ', ' . ($row->option_1 ? $row->option_1->code : '') .
                ', ' . ($row->option_2 ? $row->option_2->code : '') . ', ' . ($row->option_3 ? $row->option_3->code : '') . ', ' . ($row->option_9 ? $row->option_9->code : '');
            });

And this is what is shown screenshot

How should I do it so the values will be separated properly, if possible how can i create a list of existed values, the empty value would be hidden.

1 Answer 1

1

Collect the right array in the right order, and then do "implode"

$array = [1,2,3,4,5];

echo implode(', ', $array); // Output: 1, 2, 3, 4, 5

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.