Currently I'm working on project with Laravel(Im newbie to Laravel), where I have to take data from two tables and show them at Google Marker info window. The structure of the tables is:
Table A
companyID |
companyName |
companyAddress |
...
Table B
productID |
companyID |
productPrice |
...
Controller
$table = DB::table('tableA')
->join('tableB', 'tableB.companyID', 'tableA.companyID')
->get();
// return this to view
$array['table'][] = array(
'compID'=>$table->companyID,
'price'=>$table->productPrice
...
);
}
return view('maps')->with($array);
Blade.php
@foreach($table as $key)
var html = '<h2>Company Name : ' + '{{$key['compName']}}' + '</h2><p>' + '{{$key['price']}}' + '</p>';
var markerLatlng = new google.maps.LatLng({{$key['lat']}}, {{$key['long']}});
var mark = new google.maps.Marker({
map: map,
position: markerLatlng,
icon: '{{$key['icon']}}',
});
bindInfoWindow(mark, map, infoWindow, html);
@endforeach
I joined two tables but when I go to view file and use foreach to take every company info and product price, it shows company info and the last price of every company (e.g. if a company has 4 products, I will take only the last product and price as well).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…