Advertisement
Guest User

Untitled

a guest
Jun 7th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. // Всего 2 города
  2.         $citys = $this->city->with('goods')->get();
  3.  
  4.         $priceList = [];
  5.  
  6.         foreach ($citys as $city) {
  7.  
  8.             $cityName = $city->name;
  9.  
  10.             $priceList[$cityName] = [
  11.                 'city_id'   => $city->id,
  12.                 'price'     => []
  13.             ];
  14.  
  15.             foreach ($city->goods as $goods) {
  16.                 $priceList[$cityName]['price'][$goods->name] = [
  17.                     'goods_id'  => $goods->id,
  18.                     'weights'   => []
  19.                 ];
  20.                 echo $cityName . PHP_EOL; // Будет выведено 2 разных города
  21.                 foreach ($goods->goodsPrice as $goodsPrice) {
  22.                     echo $cityName . PHP_EOL; // А тут будет всегда только первый
  23.                     $priceList[$cityName]['price'][$goods->name]['weights'][] = [
  24.                         'weight'    => $goodsPrice->weight,
  25.                         'cost'      => $goodsPrice->cost
  26.                     ];
  27.                 }
  28.             }
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement