Update on Laravel 5 a field receiving the value of another field from the same table

Asked

Viewed 1,219 times

3

I have a configuration table in my database that has the following fields: ["id", "texto", "textoOriginal"]. Initially the field values texto are equal to the field textoOriginal, but the user can at a given time change the value of the field texto. I need to create a method that the user can reset the original values of the parameters, so I need to run this query:

UPDATE parametros SET texto = textoOriginal

But I wanted to do it for the syntax of Query Builder, it turns out that the Laravel updates the field texto with the string "textOriginal". I’m doing like this:

$this->update(['texto' => 'parametros.textoOriginal']);

Does anyone know how to do that?

  • already tried to do a query before the update that takes the value of the textOriginal ai after Voce passes this value in update $this->update(['text'=>'$Row->textOriginal]); ?

  • But then it would be too heavy, I wanted to update everything at once. But I guess there’s no way.

1 answer

2


I managed to solve the problem. For those with the same problem just put the name of the field in the expression DB::raw('column name') in this way:

$this->update(['texto' => DB::raw('textoOriginal')]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.