6
我有一个用户表和约会表。在预约表中,我有两个用户ID(customer_id,staff_id)。我想用客户名称和员工姓名检索所有约会。Laravel Eloquent渴望加载中:加入同一表格两次
users table
id
name
appointments table
id
staff_id(user_id)
customer_id(user_id)
datetime
正如你所看到的,我必须用约会表两次加入users表。 通常我会这样做内连接。
我们可以用Laravel雄辩地用()来加载吗?
我们可以这样做:
appointments::with('users' *)->get();?
* Do something here to inner join users table twice, and read user1.name as staff_name, user2.name as customer_name.
这是最后的输出我需要:
appointment_id
staff_id
staff_name
customer_id
customer_name
datetime
我还有一个问题,什么是在下面的查询第二个参数?
User::with(array(
'post'=> function() use $region {
//what is use $region means? Can you give me an example?
}
));
谢谢!