当前位置:主页 > 软件编程 > PHP代码 >

laravel orm 关联条件查询代码

时间:2021-04-25 10:09:02 | 栏目:PHP代码 | 点击:

如下所示:

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

您可能感兴趣的文章:

相关文章