Parameter query sql

0

I have the following function and would like to use the following parameter method

     public function graficos( Request $request ){
        $id = $request->input('id');
        $query = "SELECT * FROM tabela WHERE id = :id OR id = (SELECT MAX(id) FROM tabela WHERE id < :id) OR id = (SELECT MIN(id) FROM tabela WHERE id > :id)";
        $retorno = DB::select( $query, ['id' => $id ] ); 
        return response()->json( $retorno, 200 );
    }

But this message is getting: **

  

SQLSTATE [HY093]: Invalid parameter number

**

That's the way it works:

        $id = $request->input('id');
        $query = "SELECT * FROM tabela WHERE id = ? OR id = (SELECT MAX(id) FROM tabela WHERE id < ?) OR id = (SELECT MIN(id) FROM tabela WHERE id > ?)";
        $retorno = DB::select( $query, [$id, $id, $id ] ); 

I would like help solving this problem

    
asked by anonymous 25.06.2018 / 21:56

0 answers