I am using laravel to build an application. Also, I am using Eloquent ORM.
There are two tables:
meetings - id(PK), name, meeting_with, meeting_on
user_meetings - id, meeting_id (FK -meetings (id) ), user_id
{ "data" : { "meeting_details" : { "id" : 8, "name" : "Client", "meeting_with" : "CEO", "meeting_on" : 1431588871 }, "user_details" : { "2" : "Second User", "1" : "First User" } } }
This is the JSON post that I am getting. I need to update in two tables - meetings and user_meetings
I am able to update the meetings table, but not able to update user_meetings table.
foreach($meetings_data['data']['user_details'] as $user_id => $user_name) {
$update_array_set['user_id'] = $user_id;
$user_meeting_result = UserMeetingDetails::where('meeting_id', '=', $meeting_id)->update($update_array_set);
}
I get the user_id from user_details
.
So, if there are two users corresponding to one meeting_id
, and if I try to update it to only one, it updates that, but also keeps the second entry. And, if the JSON has only one object under user_details, there needs to be only one object in database corresponding to a meeting_id