I'm not sure what you mean here, because your selectedBatch method doesn't use the points scope here.
If you mean to use the scope in the withPivot method then I can already tell that this won't work.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi All
I am trying to use scope for retrieving column field name from many to many relationship's intermediate table.
Pivot Table fields are
Model - Quizzes
public function selectedBatch($batchId)
{
return $this->belongsToMany(\App\Batch::class , 'quizzes_batches', 'quiz_id', 'batch_id')
->using('App\QuizBatch')
->withPivot(
'start_date', 'end_date', 'points')
->wherePivot('batch_id', $batchId)->firstOrFail();
}
And the scope method is
public function scopePoints($query)
{
return $query->pivot->points;
}
I want to get points value (the column is in pivot table) from a particular batch (among all batches belongs to quiz).
Now when I try to retrieve following code, I am not getting any result
$quiz->selectedBatch($batchId)->marks();
Please guide me, where I am doing wrong.
Please or to participate in this conversation.