我想使用order by a relationsship来获取数据:
return $this->customer->where('status', 1)
->whereDoesntHave('activeAssignments')
->with('latestDismissal')
->join('dismissal', 'customers.id', '=', 'dismissal.customer_id')
->orderBy('dismissal.valid_at_timestamp')
->paginate(config('app.pagination'));但是如果我运行这段代码,我在customer模型中的自定义访问器就不再工作了:
此访问器的Trying to get property 'last_name' of non-object:
public function getDisplayNameAttribute()
{
if (!$this->toCareFirst()->first()->last_name) {
return 'NO NAME';
}
return trim(
$this->toCares()->get()->implode('display_name', ' & ')
);
}如果我将>select('customers.*')添加到我的查询中,它会返回数据,但相同的数据会返回4到5次...
https://stackoverflow.com/questions/51323234
复制相似问题