I'm passing an array from laravel to javascript. I am first passing the array to json as follows:
@php $takers_json = json_encode($takers); @endphp
And I'm getting the javascript as follows:
var taker = <?php echo $takers_json; ?>;
I'm traversing the array as follows:
for (var i=0;i<taker.length;i++){ }
The problem is that the taker array is the result of a where in the taker table that is related to the address table, in laravel I can access the address data as follows, for example:
$taker->address->city
In javascript when traversing the array I can access the data from the taker table as follows:
taker[i].company_name
Already the data of the relationship with the address table I am trying to access as follows:
taker[i].address.city
, but it's not working.
please share $takers code from controller, also try to log the taker in javascript.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community