Sarita Sharma
Sarita Sharma

Reputation: 253

How to update row based on two condition using eloquent in Laravel?

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.

Upvotes: 5

Views: 13059

Answers (2)

ali
ali

Reputation: 862

you can do this by make the following:

ModelName::where(['id'=>1,'user'=>'admin'])
->update(['column_name'=>'value',.....]);

Upvotes: 17

Narinder Bajwa
Narinder Bajwa

Reputation: 54

Try it

$obj=ModelName::where('id','=',1)->where('user','=','admin')->first();
if(count($obj) == 1){
   $obj->column_name=value;
   $obj->save();
}

Upvotes: 0

Related Questions