首页 文章

Laravel雄辩的多关系搜索专栏

提问于
浏览
2

试图找出如何从下面的Laravel Eloquent查询中搜索特定的表:

$user = \App\User::with('profile', 'languages', 'contacts', 'photos', 'jobs', 'offices', 'socials')->get();

我想要过滤的是用户所在的 profile table 'full_name_slug', '=', 'john-doe'

我试过像_502431那样形成 where clause 但没有成功 .

可能这很简单,但无法从所有Laravel 5文档中找到它 .

在此先感谢任何帮助干杯

1 回答

  • 5

    正确的语法

    User::whereHas('profile', function ($query) {
    
       $query->where('full_name_slug', '=', 'john-doe');
    })->get();
    

相关问题