I have a problem with a filter that I created thanks to the stackoverflow community but it does not finish working correctly, of course my fault.
This problem I am going to divide into 2 parts, because first, I need to bring the correct data to the datepicker and second I need to filter well the data that the controller method receives in order to save the data. Having said that, I will try to explain it as best as possible.
I have this datepicker, in which you can see that filter by a parameter that in this case is accepted:
<script>
// here receive the json array from PHP to JS
var daysData = <?= json_encode($data) ?>;
var newA = [];
for( j of daysData){
let start = moment(j["start"]);
let end = moment(j["end"]);
for (let m = moment(start); m.diff(end, 'days') <= 0; m.add(1, 'days')) {
newA[m.format('DD/MM/YYYY')] = j;
}
}
$('input[name="datefilter"]').daterangepicker({
isInvalidDate: function(date) {
var valid = false ; // default css class
let d = date.format("DD/MM/YYYY");
if(typeof newA[d] !== 'undefined'){
if(newA[d].acept == 1){
valid = true;
}
}
return valid;
},
isCustomDate: function(date) {
var daySettings = 'day_green';
let d = date.format("DD/MM/YYYY");
if(typeof newA[d] !== 'undefined'){
daySettings = 'day_red';
if(newA[d].acept == 0){
daySettings = 'day_orange';
}
}
return daySettings;
},
});
</script>
But I have another variable in the json that comes from the controller that is area_id, which marks the area of the users that request the vacations. With which what I would like is that apart from painting the colors that I already have encoded, just show me the data corresponding to the area, the user trying to request vacations, example: computer department, with 2 people, only those two people could see the vacations of the two of them.
Edit: part of the driver solved thanks to Javier in the comments.
//Filtro de inserción en bd.
//if($vacation != $guardadas){
if($vacation->date_from != $guardadas[0]->date_from and $vacation->date_to != $guardadas[0]->date_to || $vacation->area_id != $guardadas[0]->area_id){
$vacation->save();
$data = request()->all();
return back()->with('success','Vacaciones Solicitadas correctamente');
}else{
return back()->with('error','Fechas no disponibles');
}
return back();
First of all, thank you very much for your help and attention.
Greetings.