Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel智能阵列匹配_Php_Arrays_Laravel 5_Relationship - Fatal编程技术网

Php Laravel智能阵列匹配

Php Laravel智能阵列匹配,php,arrays,laravel-5,relationship,Php,Arrays,Laravel 5,Relationship,我在我的laravel项目中有很多关系。 我开始搜索。现在我有了更多的多维数组,我需要在所有数组中检查哪些值可用?! 因此,我的阵列: array:4 [▼ "bytype" => array:2 [▼ 0 => array:6 [▼ "id" => 1 "price" => 500 "discount_price" => null

我在我的laravel项目中有很多关系。 我开始搜索。现在我有了更多的多维数组,我需要在所有数组中检查哪些值可用?! 因此,我的阵列:

array:4 [▼
  "bytype" => array:2 [▼
    0 => array:6 [▼
      "id" => 1
      "price" => 500
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
    1 => array:6 [▼
      "id" => 3
      "price" => 1400
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
  ]
  "bymake" => array:2 [▼
    0 => array:6 [▼
      "id" => 1
      "price" => 500
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
    1 => array:6 [▼
      "id" => 3
      "price" => 1400
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
  ]
  "bymodel" => array:1 [▼
    0 => array:6 [▼
      "id" => 2
      "price" => 1500
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
  ]
  "byattribute" => array:3 [▼
    0 => array:6 [▼
      "id" => 1
      "price" => 500
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
    1 => array:6 [▼
      "id" => 2
      "price" => 1500
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
    2 => array:6 [▼
      "id" => 3
      "price" => 1400
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
  ]
]
那么,我怎样才能得到那个值(它的意思是那个数组),在这4个主数组中,哪一个是可用的呢

这样说:

  "listable" => array:2 [▼
    0 => array:6 [▼
      "id" => 1
      "price" => 500
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
    1 => array:6 [▼
      "id" => 3
      "price" => 1400
      "discount_price" => null
      "created_at" => null
      "updated_at" => null
      "pivot" => array:2 [▶]
    ]
  ]
--编辑-- 我的搜索控制器:

$original=$resquest->all();
        $searchableAttributes=$resquest->all();
        if(isset($resquest->type)){
            $type=VehicleType::find($resquest->type);
            $vehicles['bytype']=$type->vehicle()->toArray();
            unset($searchableAttributes['type']);
        }
        if(isset($resquest->make)){
            $make=VehicleMake::find($resquest->make);
            $vehicles['bymake']=$make->vehicle->toArray();
            unset($searchableAttributes['make']);
        }
        if(isset($resquest->model)){
            $model=VehicleModel::find($resquest->model);
            $vehicles['bymodel']=$model->vehicle->toArray();
            unset($searchableAttributes['model']);
        }
        if(!empty($searchableAttributes)){
            foreach ($searchableAttributes as $key => $value) {
                $attribute=VehicleAttributeValue::find($value);
                $vehicles['byattribute']=$attribute->vehicle->toArray();
                
            }
        }
车型:

public function vehicle(){
        return $this->belongsToMany('App\Vehicle','vehicles_types_vehicles','vehicle_type_id','vehicle_id');
    }

所有3个模型都是这样的,具有不同的键和表

您最好向我们展示您的模型和控制器。到目前为止您对此做了什么?如果数据来自数据库,您应该优化您的查询以获得您需要的数据,得到更多,然后再减少,这在两端都是低效的。感谢各位的回答,代码已添加,请检查。是否可以发布预期输出?我不明白你到底想要什么