【发布时间】:2021-03-21 06:03:24
【问题描述】:
我怎样才能得到 所有用户 哪些名称以给定的字符串开头,以及他们的 city 与 profile 关系在哪里等于 伦敦?
$users = User::where('name', 'LIKE', "{$searchingName}%")->with('profile')->get();
【问题讨论】:
-
使用
whereHas()函数:laravel.com/docs/8.x/…。whereHas('profile', function($subQuery){ return $subQuery->where('city', 'London'); })(假设city是列而不是另一个关系。)
标签: laravel eloquent relationship