gpt4 book ai didi

mysql - 将 Query Builder 查询转换为 Eloquent ORM

转载 作者:行者123 更新时间:2023-11-29 03:31:18 24 4
gpt4 key购买 nike

我想将当前的查询 转换为ORM。但是,我不清楚如何加入。

我当前的查询:

        $result=DB::table('tests')
->join('tests_matchs', 'tests_matchs.matched_tests_id', '=', 'tests.id')
->where('tests_matchs.user_id', '=', $UserId)
->where('tests_matchs.passed', '=', 'true')
->get();

最佳答案

假设您的关系设置正确,这应该有效:

$result = Test::with('tests_matchs' => function($query) user ($UserId){ 
$query->where('user_id', '=', $UserId)
->where('passed', '=', 'true');
})->get()

关于mysql - 将 Query Builder 查询转换为 Eloquent ORM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30159360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com