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%";