I was working on a project using laravel as my framework, Last week I was on vacation and came back to the project having a bunch (hundreds of lines) of javascript written into it by another student. It in theory works with the javascript but id want to convert it to php. Is there any way to do this? Or do I have to just write it all manually and find new ways to replicate the functions written in javascript using php?
The javascript looks like this and this is just a small part of it, this is a view of mine, not a controller and thats a big issue too and I dont think this is a very secure solution either compared to using laravel as supposed to?
`function readApts(aptBlocks, logsheetID){
const fnl = { logsheet: logsheetID, currentaptblock: 0, currentapt: 0, currentsocket: 1, apts: [] };
aptBlocks.split(',').forEach((apt, index) => { //Splits the given blocks into a list on every , and does a foreach on all of them // NN
const out = { block: apt, apt: [] };
const aptsInput = document.querySelector(`#apartmentBlock${index}`).value.replace(/s+/g, ''); //Reads the specific apartment input and removes all spaces in it // NN
if(aptsInput){ //If the input actually has any data in it // NN
const res = [];
aptsInput.split(',').forEach((apt) => { //Splits each apartment number input into a list on every , and does a foreach on each number // NN
if(apt.includes('-')){
const [start, end] = apt.split('-'); //Splits the element into 2 if it has a - // NN
for(let i = Number(start); i <= Number(end); i++){
res.push(i.toString()); //Takes every single number in between the 2 given numbers and puts them into the list // NN
}
}else{
res.push(apt.toString()); //Just pushes the number into the list if it doesnt contain a - // NN
}
});
out.apt = res;
$.ajax({ //Sends an AJAX POST request to the set route to create the apartments into the database // NN
type: "POST",
url: "{{ url('log_sheets/createapartments') }}",
async: false,
data: {
block: apt,
apts: res,
logsheet: logsheetID,
},
success: function(response){
console.log(response);
out.id = response; //Returning the ID of each apartment // NN
},
});
fnl.apts.push(out); //Saves all the info of each apartment into a bigger list // NN
}
});
$.ajax({ //Sends an AJAX POST request to the set route to save all the apartment info to the specified logsheet // NN
type: "POST",
url: "{{ url('log_sheets/updatelog') }}",
data: {
logsheet: logsheetID,
apts: fnl.apts,
},
});
$.ajax({ //Sends an AJAX POST request to the set route to save all info to the session for later use // NN
type: "POST",
url: "{{ url('log_sheets/savesession') }}",
data: {
data: fnl,
},
success:function(res){
console.log(res, fnl);
document.querySelector("#measureButton").style = "";
},
});
}`
Tried finding a solution but have not found one, thought id give this place a shot since it usually has helped people resolve their problems