someUser
2 months ago

Eager loading where query returns empty array

Posted 2 months ago by someUser

Hi there,

i am having a small issue with a where query on a relation. When ever i try to get $courses, it returns an empty array - however, if i dump the same query i'll receive the desired results.

dd($query->where('businessunit', $queryParams['filterByBusinessUnitShortName'])->get());

Here is the controller where the query is being used.

//CourseController.php

$queryParams = $request->query();

$courses = Course::whereHas('siteObject', function ($query) use ($queryParams) {
$query->where('businessunit',$queryParams['filterByBusinessUnitShortName']);
 })->get();

return $courses;

Relation on the course class

//Course class
public function siteObject() {
    return $this->belongsTo(Site::class, 'site');
}

Could anyone point me the issue here?

Please sign in or create an account to participate in this conversation.