Hello everyone, how to pass ID of Group to Retrieve all Student journals where group_id equals to current group?
// Group Model
public function students(): BelongsToMany
{
return $this->belongsToMany(Student::class)
->select('id', 'city')
->with('user')
->without('groups', 'lessons', 'journals')
->with('journals',function($q) {
$q->where('group_id', $this->id); //Not working, also tried $this->getKey()
$q->where('group_id', 3); //For example group_id=3, Working
});
}
->with('journals',function($q) {
$q->where('group_id', $this->id); //Not working, also tried $this->getKey()
$q->where('group_id', 3); //For example group_id=3, Working
});
the $q->where('group_id',... is implied (in the eager-loading query there will be a whereIn constraint based on the loaded Groups' id. It is enough to: