[英]How do I use custom attribute on scope?
Model.php
public function getClientNameAttribute()
{
return $this->client->first_name . ' ' . $this->client->last_name;
}
public function scopeSearch($query, $search)
{
return $query->where('number', 'LIKE', '%' . $search . '%')
->orWhere('client_name', 'LIKE', '%' . $search . '%');
}
我收到一個錯誤SQLSTATE[42S22]: Column not found: 1054 Unknown column 'client_name' in 'where clause'
嘗試添加
->orWhere('{table_name}.client_name', 'LIKE', '%' . $search . '%');
如果您要加入,它可能會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.