как зациклить laravel с функцией ()? - PullRequest
0 голосов
/ 09 апреля 2019

У меня есть проблема, это мой код: я редактирую свой квест.

// это все еще ошибка, потому что $ x является массивом.

$x = [$arr[0], $arr[1],$arr[2],$arr[3]]; 

вернуть $ this-> с($ x) -> где ('parent_id', '=', null) -> get ();

// все нормально.но я хочу зациклить $ arr внутри laravel с функцией.

return $this->with($arr[0], $arr[1],$arr[2],$arr[3])->where('parent_id', '=', null)->get();

1 Ответ

1 голос
/ 09 апреля 2019

Создайте отдельный массив и выполните цикл:

$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();
...