【发布时间】:2015-05-09 18:49:11
【问题描述】:
我想在 Laravel5 中使用 Elequent 从一个表及其所有相关表中进行关键字搜索。 我的控制器是
$clients = Client::with('contacts', 'paymentTerm', 'addressInfo');
if ($q = Request::input("q")) {
$clients->where("clients.name", 'LIKE', "%$q%");
$clients->where("address_info.email", 'LIKE', "%$q%");//This is not working,I want to search from both client and client address_info
}
return $clients->paginate(10);
客户端模型,
public function addressInfo() {
return $this->hasOne('App\Model\ClientAddressInfo');
}
客户地址信息,
public function client() {
return $this->belongsTo('App\Model\Client');
}
如何在这里应用关键字搜索?
【问题讨论】:
标签: php mysql laravel laravel-5