What error do you get? And how do you use the scope?
Sep 15, 2021
6
Level 7
Query builder wont accept variable
Can anyone tell me why I can not get the sub query in the function to accept the $slid parameter I pass in when calling the method?
public static function scopeNav($q, $scid, $slid)
{
return $q->where('id', $scid)
->with('studentLessons', function ($q1) use ($slid) { // i have included here
$q1->where('is_locked', false)
->where('id', '>', $slid)->dump();
})->get();
}
If I manually the value the query works fine but for some reason I can't get it accept the parameter I pass it in even though i know the value is correct.
Level 55
@naykel your problem is here
->with('studentLessons', function ($q1) use ($slid) {
it must be
->with(['studentLessons' => function ($q1) use ($slid) {
}])
2 likes
Please or to participate in this conversation.