【发布时间】:2020-12-06 20:03:04
【问题描述】:
尝试将 - 不成功 - 作为分隔值从该数组传递到视图中:
#items: array:1 [▼
0 => {#548 ▼
+"location": "Guadalajara"
+"location_id": 34
}
]
}
这个数组出现在左连接查询之后
$default_loc = DB::table('users')
->leftJoin('locations', 'users.location_id','=','locations.id')
->where('users.id',auth()->user()->id)
->select('location', 'location_id')
->get();
如果我尝试通过compact('default_loc') 将此数组传递给视图,我只能使用{{ $default_loc }} 显示整个数组,但不能将其分成$default_loc->location 和$default_loc->id .
谢谢大家,
【问题讨论】:
-
可能因为是一个数组,所以将其作为数组访问可能是一个很好的起点:
{{ $default_loc[0]->location_id }} -
就是这样。谢谢!
标签: arrays laravel collections eloquent laravel-query-builder