how to update a variable php in laravel using javascript?

<?php

use AppModelspetBreedType;

$breeds = petBreedType::all();
$hasJantan = false;

?>
 {{-- {{ dd($hasJantan) }} --}}
                <select class="" name="types[]" id="types" multiple>
                    <option value="2" {{ in_array('2', old('types', [])) ? 'selected' : '' }} {{ $hasJantan ? 'selected' : '' }}>Anjing</option>
                    <option value="1" {{ in_array('1', old('types', [])) ? 'selected' : '' }}>Kucing</option>
                </select>
<script>
    var url = window.location.href;

    function getURLParameters(url) {
    var queryString = url.split('?')[1];
    if (!queryString) {
        return {};
    }

    var params = queryString.split('&');
    var result = {};
   
    for (var i = 0; i < params.length; i++) {
        var param = params[i].split('=');
        var key = decodeURIComponent(param[0]);
        var value = decodeURIComponent(param[1]);
        
        if (result[key]) {
            if (Array.isArray(result[key])) {
                result[key].push(value);
            } else {
                result[key] = [result[key], value];
            }
        } else {
            result[key] = value;
        }
    }
    return result;
}

var parameters = getURLParameters(url);
console.log(parameters);
if (parameters['Gender[]'] && parameters['Gender[]'].length === 2) {
    console.log('Gender with two values:', parameters['Gender[]']);
} else {
    console.log('Gender doesn't have two value.');
}
var hasJantan = parameters['Gender[]'] && parameters['Gender[]'].includes('Jantan');
var hasJantan = {{ $hasJantan ? 'true' : 'false' }};
console.log(hasJantan);
</script>

this is my code in laravel, i want to update the variable hasJantan using javascript, if i console the var hasJantan in the script it return true but when i dd($hasJantan) in the blade it still return false. How can i update the variable? i’m not very good at using PHP