复杂的复合关系

时间:2016-05-30 01:06:28

标签: laravel relationship

Compoud关系(更多一个id)

$tickets = Ticket::with(['orders', 'order'])
    ->when($status == 'open' || $status == 'closed', function ($query) use ($status) {
        $query->where('tickets.open', ($status == 'open')? 1 : 0);
    })->when($type == 'Internal Message', function ($query) use ($type) {
        $query->where('type', $type);
    })->has('orders')
    ->orHas('order')

关系

public function orders()
{
    return $this->hasOne(Order::class, 'transaction_id', 'transaction_id');
}


public function order()
{
    return $this->hasOne(OrderItems::class, 'item_id', 'item_id')
        ->rightJoin('orders as o', 'order_items.order_id','=','o.id');
}

但不适用于关系订单

当我发送没有订单的查询时 - 工作时,当我发送(['订单'])字段状态不起作用并取出所有票据

0 个答案:

没有答案