laravel 5.6:我收到一个错误“语法错误或访问冲突:1064您的SQL中存在错误”

时间:2019-03-08 10:02:29

标签: php mysql laravel laravel-5 laravel-5.6

我正在开发应用程序的后端,并且我使用laravel 在恢复中,我想选择该用户的安全问题

 $User_data = User::where('email', '=', $email)->leftJoin('secutitequestion', function($join) {
            $join->on('users.id', '=', 'secutitequestion.user_id')->pluck('secutitequestion.securite_question1'
            ,'secutitequestion.answer_securite_question1'
            ,'secutitequestion.securite_question2'
            ,'secutitequestion.answer_securite_question2'
            ,'secutitequestion.securite_question3'
            ,'secutitequestion.answer_securite_question3');
        });

这就是我得到的:

  

“ SQLSTATE [42000]:语法错误或访问冲突:1064   您的SQL语法错误;检查与您的手册相对应的手册   在users上的''附近使用正确语法的MySQL服务器版本。id   = secutitequestionuser_id”位于第1行(SQL:选择secutitequestionsecurite_question1,   {{1}上的secutitequestionanswer_securite_question1users =   idsecutitequestion)”

1 个答案:

答案 0 :(得分:0)

您正在->pluck内部呼叫leftJoin,但应该在外部呼叫。请在下面尝试我的代码

$User_data = User::where('email', '=', $email)
                ->leftJoin('secutitequestion', function($join) {
                        $join->on('users.id', '=', 'secutitequestion.user_id');
                })
                ->select('secutitequestion.securite_question1'
                        ,'secutitequestion.answer_securite_question1'
                        ,'secutitequestion.securite_question2'
                        ,'secutitequestion.answer_securite_question2'
                        ,'secutitequestion.securite_question3'
                        ,'secutitequestion.answer_securite_question3')
                ->get();