我需要在管理员列表(管理员表)中显示角色名称(角色表)。我使用查询:leftJoin $data = Admin::select('admins.*', 'roles.name') ->leftJoin('model_has_roles', 'model_has_roles.model_id', '=', 'admins.id') ->leftJoin('roles', 'roles.id', '=', 'model_has_roles.role_id') ->get();在操作中,我看到以下输出:print_r($data)([id] => 1[name] => administrator[email] => m@m.com[password] => $2y$10$7/HMHGIPIJ6FiNBLy.BynurEhcsrbWkbc4wFREN9qjAFGNqSdaFTS[remember_token] => [created_at] => 2020-02-11 10:46:45[updated_at] => 2020-02-11 10:46:45[sex] => [dob] => [mobile] => [phone] => [address] => [street] => [city] => [district] => [state] => [country] => [photo] => [web] => [status] => New[upload_folder] => [deleted_at] => )这项工作,但我看不到在列表中!在“输出”中,将 替换为 。().admin nameroles nameadmin name[name] => administrator我该如何解决这个问题并显示+名称中的所有值?!admins tableroles table
1 回答
慕桂英4014372
TA贡献1871条经验 获得超13个赞
您可以别名如下roles.name
改变
$data = Admin::select('admins.*', 'roles.name')
自
$data = Admin::select('admins.*', 'roles.name as RoleName')
- 1 回答
- 0 关注
- 59 浏览
添加回答
举报
0/150
提交
取消