lundi 17 février 2020

laravel show multiple data in datatables

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.

enter image description here

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



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3bTgYKK
via IFTTT

Aucun commentaire:

Enregistrer un commentaire