Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zettz's avatar
Level 1

Displaying record using Datatables from 3 tables

Hi there, I started to use Yajra Datatables and Spatie Permission for my project, and I got confuse. But I managed to show the results with no error, like this

{"draw":0,"recordsTotal":4,"recordsFiltered":4,"data": and so on

As for the tables are: users, roles, user_has_roles. Here's the controller

public function userList()
    {
        $user = User::with('roles')->select('users.*');
        return Datatables::of($user)->make(true);
    }

Anything to change so the table will become something like this: | # | ID | username | email | roles |

for the ID, username and email, already displayed, except "roles". Note: the "user_has_roles" already include at the result without I did anything at all Thank you.

0 likes
0 replies

Please or to participate in this conversation.