Reputation: 7175
I want to update two fields in laravel 5.3.I have two fields values 'status_id' and 'comment'.my query is working is I update only 'status_id' field
DB::table('travel_request')
->where('id',$id )
->update(['status_id' => DB::table('travel_request_status')->where('status', $status)->first()->id]);
I tried to update two fields as follows
DB::table('travel_request')
->where('id',$id )
->update(['status_id' => DB::table('travel_request_status')->where('status', $status)->first()->id],['comment'=>$comment]);
Upvotes: 1
Views: 4320
Reputation: 588
Do a small change.
DB::table('travel_request')
->where('id',$id )
->update(['status_id' => DB::table('travel_request_status')->where('status', $status)->first()->id,'comment' => $comment
]);
Upvotes: 1
Reputation:
you put closure in wrong place
DB::table('travel_request')
->where('id',$id )
->update(['status_id' =>
DB::table('travel_request_status')->where('status', $status)->first()->id
,'comment'=>$comment]);
Upvotes: 1
Reputation: 3157
All fields should be in one array.
According to Laravel Documentation, The update method expects an array of column and value pairs representing the columns that should be updated.
Try
DB::table('travel_request')
->where('id',$id )
->update(['status_id' => DB::table('travel_request_status')->where('status', $status)->first()->id, 'comment'=>$comment]);
Upvotes: 1
Reputation: 163748
You're passing two arrays, but you should pass one array with two key => value
pairs as parameter:
DB::table('travel_request')
->where('id', $id)
->update([
'status_id' => DB::table('travel_request_status')->where('status', $status)->first()->id,
'comment' => $comment
]);
Upvotes: 3