I have this repository (PaymentRepository) the partial of what I'm stack at is this:
$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);
When there isn't a location picked the payment does have a relation available with client, this is what I see when dumping a record
#relations: array:1 [▼
"client" => Client {#578 ▶}
]
After a location is picked, relation is immediately broken then dumping record shows this
#relations: array:1 [▼
"client" => null
]
Though when I perform toSql to query and dump it, the result is this:
"select * from `payments`"
Does eager loading (with(array('client'=>
) break a relationship?, currently Payment class has this connection with Client class:
public function client() {
return $this->belongsTo('App\Client', 'client_id' ,'id');
}