1

I am trying to update a database column field with raw SQL in laravel. It's important to mention that the update code was written to MySQL drive but now I use Postgres. The column name is dayID. So the update code is:

DB::update("update table set travel = ... WHERE dayID = {$this->dayID}");

I must use raw SQL because I make some updates to polygon types.

The problem is that laravel automatically transforms the dayID to dayid so I get an error:

column "dayid" does not exist

I tried to set a variable in order to use it in update query but it also failed with the same error:

$var = "dayID";
DB::update("update table set travel = ... WHERE ".$var." = {$this->dayID}");

How can I fix it?

1 Answer 1

0

Please try DB::table with update below:

DB::table('table_name')
        ->where('dayID', $this->dayID)
        ->update(['travel' => '...']);

Laravel document :

https://laravel.com/docs/5.3/queries#updates

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.