我有一个问题,这是我的代码:我编辑我的任务。
//它仍然是错误,因为$ x是一个数组。
$x = [$arr[0], $arr[1],$arr[2],$arr[3]];
返回$ this-> with($ x) - > where('parent_id','=',null) - > get();
//没关系。但我想用函数在laravel里面循环$ arr。
return $this->with($arr[0], $arr[1],$arr[2],$arr[3])->where('parent_id', '=', null)->get();
创建一个单独的数组,并循环:
$array = [
[$child => function ($query) {
$query->whereIn('id', $this->collectID);
}],
[$child . '.' . $child => function ($query) {
$query->whereIn('id', $this->collectID);
}],
[$child . '.' . $child . '.' . $child => function ($query) {
$query->whereIn('id', $this->collectID);
}],
[$child . '.' . $child . '.' . $child . '.' . $child => function ($query) {
$query->whereIn('id', $this->collectID);
}],
[$child . '.' . $child . '.' . $child . '.' . $child . '.' . $child => function ($query) {
$query->whereIn('id', $this->collectID);
}]
];
// loop through $array, do what you need and than pass it to the with method below
return $this->with($array)->whereNull('parent_id')->get();