I created a simple mobile app using React Native and for the data source, I created a simple API in PHP which fetches the data from a website and provides it to the users. Now I wanted to add notifications feature in my app and for that, I always need to know which data has been updated, I solved this problem by storing my data in two different tables in my DB and then comparing the changes, which is a lengthy procedure and not very efficient in my opinion. All my previous code was written in pure PHP without using any framework. Now I wanted to implement my whole project into Laravel based backend and don't know how can I achieve the functionality means getting updated data and then using that data to further send notifications to the users.
Summary of the functionality I want: - Parse data from a website - Look for new data - If there is new data send notifications -setting cron job to repeat
My old compare script looks like this:
<?PHP
include '../config/dbData.php';
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$connect = mysqli_connect($HostName, $HostUser, $HostPass);
mysqli_select_db($connect, $DatabaseName);
mysqli_query($connect, "SET NAMES 'UTF8'") or die("ERROR: " . mysqli_error($connect));
$fetch3 = mysqli_query($connect, "SELECT * FROM timetable
WHERE id NOT IN (SELECT id FROM TimetableStudentCompare)
UNION
SELECT * FROM TimetableStudentCompare
WHERE id NOT IN (SELECT id FROM timetable)
UNION
SELECT * FROM timetable
WHERE Vertreter NOT IN (SELECT Vertreter FROM TimetableStudentCompare)
UNION
SELECT * FROM TimetableStudentCompare
WHERE Vertreter NOT IN (SELECT Vertreter FROM timetable)
UNION
SELECT * FROM timetable
WHERE Std NOT IN (SELECT Std FROM TimetableStudentCompare)
UNION
SELECT * FROM TimetableStudentCompare
WHERE Std NOT IN (SELECT Std FROM timetable)
UNION
SELECT * FROM timetable
WHERE Klasse NOT IN (SELECT Klasse FROM TimetableStudentCompare)
UNION
SELECT * FROM TimetableStudentCompare
WHERE Klasse NOT IN (SELECT Klasse FROM timetable)");
$array3 = array();
while ($row3 = mysqli_fetch_assoc($fetch3)) {
$array3[] = $row3;
}
echo json_encode($array3, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
// Fetching Klassen to a new array
$KlasseArray = array();
foreach ($array3 as $value) {
array_push($KlasseArray, $value['Klasse']);
}
// array only with classes
print_r($KlasseArray);
//Removing Duplicates
$list = $KlasseArray;
sort($list);
foreach ($list as $k => $v) {
if (isset($check)) {
if ($check === $v) {
unset($list[$k]);
}
}
$check = $v;
}
$noDuplicate = array_values($list);
// Result klassen with no duplicates
print_r($noDuplicate);
mysqli_close($connect);
Can anyone please help me with this?
</div>