Search code examples
phpdatatablelaravel-8

Seperate or space between the two values in one cell in Datatable (Laravel 8)


I have a query from Database which is John and Mary under display_name. For (ID 1 = John)(ID 2 = Mary) I have a data on view that contain two values or ID in one cell using AJAX Datatable based on this picture.

Cell in Datatable

Database ID 1 : John , ID 2 : Mary

How can I seperate or make a space between this two values that bring ID on view Datatables ? I want to make "John Mary" instead of "JohnMary" in one cell column.

Here is my Index datatable code:

->addColumn('roles', function($record){    
                $data='';
                if($record->role()->get()){
                    foreach ($record->role()->get() as $role){
                        $data .= $role->display_name;
                    }
                }
                return $data;
            })

Solution

  • Adding a space after your name will do the trick:

    $data .= $role->display_name . ' ';