Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Keldarne's avatar

Multiple where clause not working

Hi everyone,

I have this code to delete an object contained in 2 tables :

    public function deleteCriteria(Request $request)
    {
        $token = $request->input('token');
        $criteria = $request->input('criteria');
        $isSuccess = 0;
        $error = 'no error';
        if (User::where('remember_token', $token)->get()->first()->id !== null) {
            try {
                DB::connection()->enableQueryLog();
                DB::table('project_gate_criteria')
                    ->where(array(
                        'fk_gate_criteria', $criteria['fk_gate_criteria'],
                        'fk_project_gate', $criteria['fk_project_gate']
                    ))
                    ->delete();

                DB::table('gate_criteria')
                    ->where(
                        'id', $criteria['gate_criteria']['id']
                    )
                    ->delete();
                $isSuccess = 1;
            } catch (Exception $exception) {
                $error = $exception->getMessage();
            }
        }
        return '{"requestStatus":"' . $isSuccess . '","error":"' . $error . '"';
    }

This code should work as far as I know but I get this error :

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: delete from `project_gate_criteria` where (`0` = fk_gate_criteria and `1` = 35 and `2` = fk_project_gate and `3` = 1))

As I understand this error this is laravel not creating request correctly, but I don't know if it's laravel building request wrong or me doing something wrong in my code.

0 likes
1 reply
tykus's avatar

If you are passing an array to a where method, then the syntax is => is required to map the field name to the value (testing for equality is assumed):

// ...
    ->where(array(
        'fk_gate_criteria' => $criteria['fk_gate_criteria'],
        'fk_project_gate' => $criteria['fk_project_gate']
    ))
// ...

Please or to participate in this conversation.