Level 14
How about ->wherePivotIn?
$this->models->filter(function ($model) {
return $model->wherePivotIn('pivotcolumn', ['one', 'two', 'three'])
})->values();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
What is the shorten version of this :
$this->models->filter(function ($model) {
return $model->pivot->pivotcolumn == 'one' or
$model->pivot->pivotcolumn == 'two';
})->values();
it will work but what if i want filter through over three or more pivot table ? When i using return $model->pivot->pivotcolumn == 'one' or 'two' it return all result and wouldnt filter it.
How about ->wherePivotIn?
$this->models->filter(function ($model) {
return $model->wherePivotIn('pivotcolumn', ['one', 'two', 'three'])
})->values();
Please or to participate in this conversation.