【发布时间】:2019-05-13 06:52:25
【问题描述】:
For 循环不工作 $AllPathsTasgs 有 2 个数组所以 count($AllPathsTasgs) 将返回 2 个我的并且我返回 2 个路径所以它应该首先使用
$x == 0
那么应该使用
$x == 1
但它使用
$x == 1
对于拖车,路径不知道为什么
虽然我用过 dd($x);它正确返回 $x
请帮忙
foreach ($paths as $path){
$AllPathsTasgs[] = $path->pathtags->pluck('name');
}
$posts3 = Path::with(['ProgrammingField','pathtags' => function ($q) use ($AllPathsTasgs) {
for ($x = 0; $x < count($AllPathsTasgs); $x++) {
if ($x == 0) {
$q->with(['Tasks' => function ($q) use ($AllPathsTasgs, $x) {
$q->has('tasktags', '=', 2)
->orderBy('id', 'ASC')
->whereDoesntHave('tasktags', function ($query) use ($AllPathsTasgs, $x) {
$query->whereNotIn('name', $AllPathsTasgs[0]);
})->with('tasktags')->orderBy('id', 'ASC');
}]);
}
if ($x == 1) {
$q->with(['Tasks' => function ($q) use ($AllPathsTasgs, $x) {
$q->has('tasktags', '=', 2)
->orderBy('id', 'ASC')
->whereDoesntHave('tasktags', function ($query) use ($AllPathsTasgs, $x) {
$query->whereNotIn('name', $AllPathsTasgs[1]);
})->with('tasktags')->orderBy('id', 'ASC');
}]);
}
}
}])->whereIn('id',$pathId)->get();
【问题讨论】:
标签: php laravel loops for-loop eloquent