早上好!我有一个问题,下面的json,我收到这个
{"id":51,"nif":"","name":"","cognoms":"","file":"uploads\/$usuario->id\/$fileName","birthday":"0000-00-00","presentacion":"desde","email":"[email protected]","idempresa":1,"id_poblacion":826,"id_online":0,"created_at":"2015-05-23 23:53:46","updated_at":"2015-05-23 23:53:46","municipio":{"id":826,"idprovincia":29,"poblacion":"Castellitx","poblacionseo":"castellitx","postal":7210,"latitud":"39.562691","longitud":"2.882967"},"bids":[{"id":36,"nombre":"asdsfasd","descripcion":"fsdafsdafsdfsa","precio_salida":170,"cant_actual":172,"id_estado":1,"id_metode_envio":2,"id_metodo_pago":1,"id_creador":51,"id_ganador":null,"id_categoria":34,"id_adquirido":0,"data_inici":"2015-05-30","durada":null,"created_at":"2015-05-24 19:06:19","updated_at":"2015-05-24 20:26:56"}]}<p>233.81707298156</p> {"id":37,"nif":"","name":"","cognoms":"","file":"uploads\/claves.png","birthday":"2015-05-05","presentacion":"asdasdasfafsadfa","email":"","idempresa":1,"id_poblacion":23,"id_online":0,"created_at":"2015-05-22 09:16:33","updated_at":"2015-05-25 08:40:03","municipio":{"id":23,"idprovincia":1,"poblacion":"Barrundia","poblacionseo":"barrundia","postal":1206,"latitud":"42.917229","longitud":"-2.495040"},"bids":[{"id":37,"nombre":"asdffsa","descripcion":"fsadfsdafa","precio_salida":187,"cant_actual":187,"id_estado":1,"id_metode_envio":1,"id_metodo_pago":1,"id_creador":37,"id_ganador":null,"id_categoria":34,"id_adquirido":0,"data_inici":"0000-00-00","durada":null,"created_at":"2015-05-24 19:07:26","updated_at":"2015-05-24 19:07:26"},{"id":38,"nombre":"dsfsdafdsfas","descripcion":"asdfdsagafgfdga","precio_salida":190,"cant_actual":190,"id_estado":1,"id_metode_envio":2,"id_metodo_pago":1,"id_creador":37,"id_ganador":null,"id_categoria":35,"id_adquirido":0,"data_inici":"0000-00-00","durada":null,"created_at":"2015-05-24 19:08:01","updated_at":"2015-05-24 19:08:01"},{"id":39,"nombre":"vcxvcvzxc","descripcion":"sdvzxvcxvz","precio_salida":300,"cant_actual":300,"id_estado":1,"id_metode_envio":2,"id_metodo_pago":1,"id_creador":37,"id_ganador":null,"id_categoria":33,"id_adquirido":0,"data_inici":"0000-00-00","durada":null,"created_at":"2015-05-24 19:08:27","updated_at":"2015-05-24 19:08:27"}]}<p>420.31608445891</p>
当我在这个表单中使用foreach时,信息显示正确
@foreach ($output as $auction)
@if(count($auction> 0))
{{$auction}}
@endif
@endforeach
但是,当我打电话来的时候,拉威尔显示出一个错误。
{{$auction->auctions}}
我不知道当我把{{$auction->auctions}laravel返回一个错误时,有人能帮我解决这个问题吗?是一对恋情。
接收此json的控制器是
public function prodcercanos($lat,$long)
{
$cercanos = User::with('municipio')->with('subastas')->get();
$coordA = Geotools::coordinate([$lat,$long]);
$output = [];
foreach ($cercanos as $p) {
if(count($p->subastas)>0){
$coordB = Geotools::coordinate([$p->municipio->latitud,$p->municipio->longitud]);
$distance = Geotools::distance()->setFrom($coordA)->setTo($coordB);
$dis = $distance->in('km')->haversine();
$output[$dis] = $p."<p>$dis</p>";
}
}
ksort($output);
return view('frontend.prodcercanos2')->with('output',$output)
最佳答案
在json中,不维护对象类型。调用$auction->auction
不会产生任何结果,因为auction
对象可能来自StdObject
类型。
另外,我不知道这是粘贴的代码中的错别字还是实时代码中的错别字,但是:@if(count($auction> 0))
不会起作用的。您的>
函数中有比较运算符(count()
)。