Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 5.1 : how can i update one row only with where clause?

I want update a row with only where clause. I don't have row id, only i have 2 where clause. Is it possible? (with eloquent)

->where("x",1) ->where("y"=2)
like image 856
Hamid Naghipour Avatar asked Oct 28 '25 06:10

Hamid Naghipour


1 Answers

When using Active Record, you should never perform an update directly in the database. First pull the record from the database, then update it:

Model::where(['x' => 1, 'y' => 2])->first()->update([...]);

If you instead do the update directly in the database, none of the ORM functionality will trigger (such as firing events or touching parents).

like image 188
Joseph Silber Avatar answered Oct 31 '25 10:10

Joseph Silber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!