public function C_Return($name, $movieName) { $client = new Client(); $movie = new DVD(); $time = new DateTime(); $clientData = $client->getClient($name); $movieData = $movie->getMovie($movieName); // If selected client and movie is reachable: if (isset($clientData[0]) || isset($movieData[0])) { $recentStatus = last($clientData[0]['Details'])['Status']; $recentMovie = last($clientData[0]['Details'])['Movie']; // If correct rental status and movie at most recent detail: if ($recentStatus == 'Rented' && $recentMovie == $movieName) { // Set input data to client details $input = ['Movie' => $movieName] + ['Status' => 'Returned'] + ['Date' => $time->format('Y-m-d H:i:s')]; // Add rental to client collection // If client edit successfully: if ($client->addMovie($input, $name)) { response()->json(['status' => 'success'], 201); // Edit movie status to available // If movie edit successfully: if ($movie->editMovie(['Status' => 'YES'], $movieName)) { return response()->json(['status' => 'success'], 200); } else { return response()->json(['status' => 'Failed to edit movie'], 404); } } else { return response()->json(['status' => 'Failed to add movie'], 404); } // Otherwise, most recent of client's details are incorrect: } else { return response()->json(['status' => 'Details incorrect'], 403); } // Otherwise, return failure of client or movie is not found: } else { return response()->json(['status' => 'Client or Movie not found'], 404); } }