BookmarkController.php
This handles the storing and retrieving of JSON bookmark data associated with a user's ID.
storeBookmark
storeBookmarkpublic function storeBookmark(Request $request)
{
// Get the JSON data from the request
$jsonData = $request->input('jsonData');
// Decode the JSON data into an associative array
$jsonData = json_decode($jsonData, true);
// Specify the directory where bookmark files will be stored
$directory = 'Bookmark';
// Construct the file path based on the user's ID
$fileBookmark = $directory . '/' . $jsonData['USER_ID'] . '.json';
// Convert the array back to pretty-printed JSON format
$prettyPrintedJson = json_encode($jsonData, JSON_PRETTY_PRINT);
// Open the file for writing
$file = fopen($fileBookmark, 'w');
// Check if the file was successfully opened
if ($file) {
// Write the pretty-printed JSON data to the file
fwrite($file, $prettyPrintedJson);
// Close the file
fclose($file);
}
// Prepare a success response
$response = [
'SUCCESS' => 1,
];
// Return the response
return $response;
}getBookmark
getBookmarkLast updated