5

I have a table : Profile Table has one foreign key and primary key. I want to update row based on two condition . Like : where ( id == 1 and user == 'admin')

How to use two para meter in update query using eloquent.

1

2 Answers 2

17

you can do this by make the following:

ModelName::where(['id'=>1,'user'=>'admin'])
->update(['column_name'=>'value',.....]);
2
  • getting error - SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause'
    – Kamlesh
    Commented Jan 24, 2023 at 11:24
  • Could you provide me with what you wrote ?
    – ali
    Commented Jan 26, 2023 at 6:11
0

Try it

$obj=ModelName::where('id','=',1)->where('user','=','admin')->first();
if(count($obj) == 1){
   $obj->column_name=value;
   $obj->save();
}
1
  • this just updates all rows with user = admin from my tests
    – qwertzman
    Commented Oct 11, 2019 at 19:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.