LaraSell
4 months ago
608
8
General

laravel show multiple data in datatables

Posted 4 months ago by LaraSell

I work with laravel spatie permission package and need to show user role for each user in datatables lists. now I add datatables addColumn method:

$items = Admin::orderBy('id','DESC');

return DataTables::of($items)
->addColumn('role',function(Admin $admin){

    foreach($admin->getRoleNames() as $v){
        return $v;
    }

})
->toJson(); 

this code work and show role name for each user but If user have a two role name(multiple roles) My code not work and show only first role name. ie: for user test I have two roles name: moderator and editor But i see only moderator.

How to can i show multiple roles name for each user in datatables list?!

Please sign in or create an account to participate in this conversation.