我有一个表Uuids
,它与dealers, masterdealers, admins and customers
表有一个变形关系。我需要从uuids表中获取所有上述用户类型表中的电子邮件地址及其uuids。我使用工会来获取经销商,经销商,管理员和客户表的所有电子邮件,但我也想以某种方式加载他们的uuids。
我想要的输出是这样的:
{
email: 1@example.com
uuid: 1
}, {
email: 2@example.com
uuid: 5
}, {
email: 3@example.com
uuid: 11
}
我试过了:
DB::select("SELECT email FROM customers
UNION SELECT email FROM dealers
UNION SELECT email FROM masterdealers
UNION SELECT email FROM admins");
它给了我这4张桌子的所有电子邮件。
答案 0 :(得分:2)
您需要加入变形表才能获得不同模型的uuids
<NavLink to={'/dashboard/profile/' + (tab.url) + '/' + userId} activeClassName="selectedTab">
<div>{tab.name}</div>
</NavLink>
另外,要在laravel中运行原始查询,您可能需要SELECT u.uuid,c.email
FROM customers c
JOIN Uuids u ON c.id = u.some_mapped_col AND u.some_morph_col = 'Model Name'
UNION
SELECT u.uuid,d.email FROM dealers d
JOIN Uuids u ON d.id = u.some_mapped_col AND u.some_morph_col = 'Model Name'
UNION
SELECT u.uuid, m.email FROM masterdealers m
JOIN Uuids u ON m.id = u.some_mapped_col AND u.some_morph_col = 'Model Name'
UNION
SELECT u.uuid, a.email FROM admins a
JOIN Uuids u ON a.id = u.some_mapped_col AND u.some_morph_col = 'Model Name'