如下所示: public function a(){ return $this-belongsTo('App\Models\a', 'aid');}$model = $this-whereHas('a', function ($query) use ($search) { $query-where('username', 'like', '%' . $search['username'] . '%');})-with(['a:id,username'])-
如下所示:
public function a() { return $this->belongsTo('App\Models\a', 'aid'); } $model = $this->whereHas('a', function ($query) use ($search) { $query->where('username', 'like', '%' . $search['username'] . '%'); })->with(['a:id,username'])->get();
laravel orm 关联条件查询
sql 语句:
select a.id,a.username,b.* from b left join a on a.id = b.aid where a.username like "%username%";
以上这篇laravel orm 关联条件查询代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。