Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Всего 2 города
- $citys = $this->city->with('goods')->get();
- $priceList = [];
- foreach ($citys as $city) {
- $cityName = $city->name;
- $priceList[$cityName] = [
- 'city_id' => $city->id,
- 'price' => []
- ];
- foreach ($city->goods as $goods) {
- $priceList[$cityName]['price'][$goods->name] = [
- 'goods_id' => $goods->id,
- 'weights' => []
- ];
- echo $cityName . PHP_EOL; // Будет выведено 2 разных города
- foreach ($goods->goodsPrice as $goodsPrice) {
- echo $cityName . PHP_EOL; // А тут будет всегда только первый
- $priceList[$cityName]['price'][$goods->name]['weights'][] = [
- 'weight' => $goodsPrice->weight,
- 'cost' => $goodsPrice->cost
- ];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement