用 Laravel 和两个 WHERE 条件查询两个表

Query two tables with Laravel and two WHERE conditions

我有 table orders 和 table payments。我想查询 table orders,加入 table payments 并显示订单已支付,哪些未支付。

这是订单模型

class Order extends Eloquent {
     protected $table = 'orders';
     protected $primaryKey = 'order_id';

     public function paidorders() {
         return $this->hasMany('payments', 'processed');
     }
}

这是支付模式

class Payment extends Eloquent {
     protected $table = 'payments';
     protected $primaryKey = 'paymentID';

     public function orders()
     {
         return $this->hasMany('Order', 'user_id');
     }
}

和用户模型

public function orders() {
    return $this->hasMany('Order', 'user_id');
}

这就是我如何只显示当前没有状态 paid/not 已付款的订单。

  $orders = self::$user->orders()->get();
     return View::make('site.users.orders', [
        'orders' => $orders
     ]);

这是查询,但我不知道如何在 Laravel

中实现它
SELECT orders. * , payments. * 
FROM orders
   INNER JOIN payments ON orders.user_id = payments.userID
WHERE orders.user_id =2
AND payments.userID =2

self::$user->... 是登录用户。如何在 WHERE 子句中使用它?

我不明白如何构建此查询

更新dd($orders)

object(Illuminate\Database\Eloquent\Collection)#264 (1) { ["items":protected]=> array(1) { [0]=> object(Order)#260 (20) { ["table":protected]=> string(6) "orders" ["primaryKey":protected]=> string(8) "order_id" ["connection":protected]=> NULL ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(1) { ["processed"]=> string(1) "1" } ["original":protected]=> array(1) { ["processed"]=> string(1) "1" } ["relations":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["fillable":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } ["dates":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(true) } } }
Try this query code:-

$users = DB::table('orders')
            ->join('payments', 'orders.user_id', '=', 'payments.userID')
            ->where('orders.user_id', '2')
            ->where('payments.userID', '2')
            ->select('orders.*', 'payments.*')
            ->get();
$query = Order::select(DB::Raw('payments.processed'))
    ->join('payments', 'orders.order_id', '=', 'payments.orderID')
    ->where('orders.user_id',  2)
    ->where('payments.userID', 2)
    ->get();