Laravel 5.0渴望加载打破关系

时间:2016-02-01 19:30:15

标签: php laravel eloquent

我有这个存储库(PaymentRepository)我所堆叠的部分内容是:

$location_id = \Request::get('location');
$transactions = Payment::where($paymentCondition)->with(array(
    'client' => function($query) use ($location_id) {
        if($location_id) $query->where('location_id', $location_id);
    }))->paginate(50);

如果没有选择地点,付款确实与客户有关系,这就是我在转储记录时看到的

#relations: array:1 [▼
    "client" => Client {#578 ▶}
]

选择一个位置后,立即断开关系,然后转储记录显示此

#relations: array:1 [▼
    "client" => null
]

虽然当我执行toSql查询并转储它时,结果如下:

"select * from `payments`"

急切加载(with(array('client'=>)会破坏关系吗? 目前Payment类与Client类具有此连接:

public function client() {
    return $this->belongsTo('App\Client', 'client_id' ,'id');
}

0 个答案:

没有答案