Php 质疑雄辩的拉威尔

Php 质疑雄辩的拉威尔,php,laravel,laravel-5,Php,Laravel,Laravel 5,我需要在雄辩的Laravel中转换这个SQL查询 Select * from modulo where idmodulo not in (select idmodulo from moduloperfil where moduloperfil.idperfil = 2) 编号2是$request正如评论中指出的,这不是雄辩的 elount是Laravel使用的活动记录实现 也就是说,如果您想使用Laravel的Fluent query builder,您可以执行以下操作: DB::table(

我需要在雄辩的Laravel中转换这个SQL查询

Select * from modulo where idmodulo not in
(select idmodulo from moduloperfil where moduloperfil.idperfil = 2)

编号
2
$request

正如评论中指出的,这不是
雄辩的

elount
是Laravel使用的活动记录实现

也就是说,如果您想使用Laravel的Fluent query builder,您可以执行以下操作:

DB::table('modulo')
    ->whereExists(function ($query) {
        $query->select(DB::raw(1))
            ->from('moduloperfil')
            ->where('moduloperfil.idperfil', '2')
            ->whereRaw('modulo.idmodulo = moduloperfil.idmodulo');
    })
->get();
上面使用的是
whereExists
而不是
wheres
,但是应该会给出相同的结果

希望这有帮助

你可以试试这个

$result = Modulo::whereNotIn('idmodulo', function ($query) {
        $query->selectRaw('idmodulo from moduloperfil where idperfil = 2');
    })->get();

您的
模型在哪里?您也可以使用。modulo是我的模型Hooo它准备好了,这是我的解决方案抱歉,请看$result=\DB::table('modulo')->whereNotIn('modulo.idmodulo',function($query)use($request){$query->select('modulerpil.idmodulo')->from('modulerpil')->where('moduleOperFil.idperfil','=',$request->perfilselecionado);})->get()这甚至不是很有说服力,也没有使用
模型
-它只使用了Laravel的查询生成器。您可以在询问之前阅读更多内容。谢谢。请添加解释这将从
ModulerFil
中选择所有
idModule
,其中'idperfil'=2,然后Module将查找除匹配值以外的所有结果。有些g like Modulo::whereNotIn('idmodulo',[1,2,3,4])->get();将不包括匹配的数据。