Feb 13, 2020
0
Level 1
Updating JSON through input
Currently working on a booking system for meetings. I am trying to update my JSON structure with an input to change the meetings values such as: duration, numberOfPeople etc. I know that i should use
$json = json_encode(file_get_contents($path), true);
{
"pinkroom": {
"name": "The pink room",
"tag": "pinkroom",
"capacity": 5,
"phone": true,
"tv": false,
"projector": true,
"wheelchairacess": true,
"meetings": [
{
"timeSlot": "9:00-9:30",
"booked": true,
"numberOfPeople": 2,
"duration": 30,
"meetingName": "React Front-End Meeting",
"bookerName": "Eric Diedrichs"
},
{
"timeSlot": "9:30-10:00",
"booked": false,
"numberOfPeople": null,
"duration": null,
"meetingName": null,
"bookerName": null
},
public function bookroom() {
$path = storage_path() . "/json/meeting.json";
$json = json_decode(file_get_contents($path), true);
$selectedRoom = $_GET['meeting'];
$roomDetails = [];
foreach ($json as $key => $values) {
if( $values["tag"] == $_GET['meeting'] ) {
array_push($roomDetails, $values);
}
}
$data = [
'roomDetails' => $roomDetails,
'selectedRoom' => $selectedRoom
];
if( submit button pressed ){
send numberOfPeople to json
send duration to json
etc...
}
return view ('meetings.bookroom')->with($data);
}
Would i just need to create an if statement inside my controller to check if input has been submited then json_encode?
Please or to participate in this conversation.