add column to datatable
{
    $query = Comment::with('user')
        ->where('model', $model)
        ->where('model_id', $model_id)
        ->orderBy('id', 'desc');

    return DataTables::of($query->get())
        ->addColumn('user_roles', function ($comment) {
            return $comment->user->getRoleNames()->implode(', ');
        })
        ->toJson();
}
we can add new column to datatable json data using this
by Giorgi Ivanidze
10 months ago
PHP
Laravel
datatable
0
Pro tip: use ```triple backticks around text``` to write in code fences