我想在Laravel口才模型中使用AS
关键字,
这里是我的示例查询:
User::find(1)
->select("name", "age")
->join("profile as p", "p.user_id", "=", "users.id")
->orderBy("name", "asc")
->get();
与主表/模型的联接上的预期用法u.id
而非users.id
->join("profile as p", "p.user_id", "=", "u.id")
有这样的功能吗?
答案 0 :(得分:2)
像这样雄辩地使用from
方法
User::from('users as u')->find(1)
->select("name", "age")
->join("profile as p", "p.user_id", "=", "u.id")
->orderBy("name", "asc")
->get();
请参见此查询雄辩的方法here