嗨,我需要在一个表用户中生成两个比较,例如我有不同级别的表用户
ID name email level
-------+-------------+------------------+--------------
34 Jhon Fus [email protected] 1 (Medic)
35 Michael Chi [email protected] 2 (Client)
该表存储订单
ID client_id medic_id status created_at
---+-----------+------------+--------+-------
1 35 34 ok 2015-07-22 19:34:59
2 35 34 ok 2015-07-23 19:34:59
预期产量
order id cliname status **medname** created
---------+-------------+--------+------------+-------
1 Michael Chi ok Jhon Fus 2015-07-22 19:34:59
2 Michael Chi ok Jhon Fus 2015-07-23 19:34:59
我尝试这样做,但是出了点问题:
$orders= Order::join('users', 'users.id', '=', 'orders.client_id')
->join('users as usmedics', 'usmedics.id', '=', 'orders.medic_id')
->select(array('orders.id', 'users.name as cliname', 'orders.status', 'usmedics.name as medname' , 'orders.created_at'))
->orderBy('orders.created_at', 'DESC');
任何想法请...
最佳答案
简单只需编写一个普通查询:
$sql = "Query as you'd write it normally...";
$result = DB::select( DB::raw($sql));
如果需要,您仍然可以使用绑定:
$sql = "SELECT * FROM tbl1 WHERE user_id = :user_id and thing2 = :thing2";
$sqlBindings=[ 'user_id' => $user_id, 'thing2' => $thing2 ];
$result = DB::select( DB::raw($sql), $sqlBindings);
关于php - Laravel 5加入同一张 table ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31835320/