Php Laravel:使用数据库字段更改变量的内容

Php Laravel:使用数据库字段更改变量的内容,php,mysql,laravel,Php,Mysql,Laravel,我有拉威尔密码 在代码中,我有变量$latitude1和longitude1,这个变量有静态内容,比如'108.2251681' $maps = Gmaps_Geocache::all(); $latitude1 = -7.325374900000001; $longitude1 = 108.2251681; $latitude2 = -7.331842799999999; $longitude2 = 1

我有拉威尔密码 在代码中,我有变量$latitude1和longitude1,这个变量有静态内容,比如'108.2251681'

$maps = Gmaps_Geocache::all();

        $latitude1 = -7.325374900000001;    
        $longitude1 = 108.2251681;

        $latitude2 = -7.331842799999999;        
        $longitude2 = 108.2237382;

        $dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$latitude1.",".$longitude1."&destinations=".$latitude2.",".$longitude2."&key=AIzaSyCyUBu8OPh0adMWbL9McFMMDqJA9UB7jes");

如何更改变量的内容“108.2251681”并立即从字段数据库中获取?

我正在解决它,我将它放在视图中

<table border="1">
            <tr>
                <th>Address</th>
                <th>Latitude</th>
                <th>Longitude</th>
                <th>Jarak</th>
            </tr>
            @foreach($maps as $m)
            <tr>
                    @php
                        $latitude1 = -7.325374900000001;;   
                        $longitude1 = 108.2251681;

                        $latitude2 = $m->latitude;      
                        $longitude2 = $m->longitude;

                        $dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$latitude1.",".$longitude1."&destinations=".$latitude2.",".$longitude2."&key=AIzaSyCyUBu8OPh0adMWbL9McFMMDqJA9UB7jes");

                        $json = json_decode($dataJson);
                        $nilaiJarak = $json->rows[0]->elements[0]->distance->text;
                    @endphp
                <td>{{ $m->address }}</td>
                <td>{{ $m->latitude }}</td>
                <td>{{ $m->longitude }}</td>
                <td>{{ $nilaiJarak }}</td>
            </tr>
            @endforeach
        </table>

地址
纬度
经度
雅拉克
@foreach(地图为百万美元)
@php
$latitude1=-7.32537490000001;;
$longitude1=108.2251681;
$latitude2=$m->latitude;
$longitude2=$m->longitude;
$dataJson=file\u get\u contents(“https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=“$latitude1.”、“$longitude1.”和destinations=“.$latitude2.”、“$longitude2.”和key=AIzaSyCyUBu8OPh0adMWbL9McFMMDqJA9UB7jes”);
$json=json_decode($dataJson);
$nilaiJarak=$json->rows[0]->elements[0]->distance->text;
@endphp
{{$m->address}
{{$m->纬度}
{{$m->经度}
{{$nilaiJarak}
@endforeach

不清楚您想做什么。是否要使用数据库中的值而不是静态值?比如maybe
$map=Gmaps\u geograche::find(1)$longitude1=$map->longitude