gpt4 book ai didi

mysql - 如何在 Eloquent 中重命名属性?

转载 作者:行者123 更新时间:2023-11-29 11:01:15 26 4
gpt4 key购买 nike

           Select distinct
`users`.`name` as user_name,
`practices`.`name` as practice_name,
`userlevels`.`name` as userlevel_name,
`usertypes`.`name` as usertypes_name,
`users`.`active` as user_status,
`users`.`email` as user_email
from `network_user`
left join `users` on `network_user`.`user_id` = `users`.`id`
left join `practice_user` on `users`.`id`=`practice_user`.`user_id`
left join `practices` on `practice_user`.`practice_id`=`practices`.`id`
left join `userlevels` on `users`.`level`=`userlevels`.`id`
left join `usertypes` on `users`.`usertype_id`=`usertypes`.`id`
where `network_user`.`network_id`= 9
;

这是我的 sql 原始查询,我是 eloquent 面临的问题的新手,任何人都可以告诉我如何在 eloquent 中重命名属性。提前谢谢。

最佳答案

请尝试这个:

$users = DB::table('network_user')
->leftJoin('users', 'users.id', '=', 'network_user.user_id')
->leftJoin('practice_user', 'practice_user.user_id', '=' ,'users.id')
->leftJoin('practices', 'practices.id', '=', 'practice_user`.`practice_id')
->leftJoin('userlevels', 'userlevels.id', '=', 'users.level')
->leftJoin('usertypes', 'usertypes.id', '=', 'users.usertype_id')
->where('network_user.network_id', 9)
->get(['users.name as user_name',
'practices.name as practice_name',
'userlevels.name as userlevel_name',
'usertypes.name as usertypes_name',
'users.active as user_status',
'users.email as user_email']);

尚未测试,但应该可以。

关于mysql - 如何在 Eloquent 中重命名属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42203134/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com