Laravel eloquent 多关系搜索列
Laravel eloquent multi relations search column
试图找出如何从下面的 Laravel Eloquent 查询中搜索特定的 table:
$user = \App\User::with('profile', 'languages', 'contacts', 'photos', 'jobs', 'offices', 'socials')->get();
我要过滤的是 个人资料 table 'full_name_slug', '=', 'john-doe'
中的用户
我试过像 'profile.full_name_slug', '=', 'john-doe'
那样构造 where 子句 但没有成功。
可能这很简单,但无法从所有 Laravel 5 文档中弄清楚。
在此先感谢您的帮助
干杯
正确的语法
User::whereHas('profile', function ($query) {
$query->where('full_name_slug', '=', 'john-doe');
})->get();
试图找出如何从下面的 Laravel Eloquent 查询中搜索特定的 table:
$user = \App\User::with('profile', 'languages', 'contacts', 'photos', 'jobs', 'offices', 'socials')->get();
我要过滤的是 个人资料 table 'full_name_slug', '=', 'john-doe'
我试过像 'profile.full_name_slug', '=', 'john-doe'
那样构造 where 子句 但没有成功。
可能这很简单,但无法从所有 Laravel 5 文档中弄清楚。
在此先感谢您的帮助 干杯
正确的语法
User::whereHas('profile', function ($query) {
$query->where('full_name_slug', '=', 'john-doe');
})->get();