this is my tables look like
departments | course | subjects |
---|---|---|
id | id | id |
head | department_id | course_id |
course_name | subject_code |
in my models this is how I do it but seems not working and I don’t know why:
public function departments(){
return $this->hasOneThrough(
subjectlist::class,
department::class,
'id',
'course_id',
'id',
'id'
);
the ouput when I try to user hasOneThrough:
{
"id": 1,
"department_name": "Business",
"head": "John smith",
"email": "[email protected]",
"contact_number": "09300282103",
"created_at": null,
"updated_at": null,
"subject_list": {
"id": 1,
"course_id": 1,
"subject_code": "Math1",
"description": "math test",
"year_type": 1,
"price": "200.00",
"units": "5.00",
"created_at": null,
"updated_at": null,
"laravel_through_key": 1
}
},
I wan’t the output should be like this please help me how to do it:
{
"id": 1,
"department_name": "Business",
"head": "John smith",
"email": "[email protected]",
"contact_number": "09300282103",
"created_at": null,
"updated_at": null,
"subject_list": {
"id": 1,
"course_id": 1,
"subject_code": "Math1",
"description": "math test",
"year_type": 1,
"price": "200.00",
"units": "5.00",
"created_at": null,
"updated_at": null,
"laravel_through_key": 1
},
department {
"id" : 1,
"department_name" : "ComputerScience"
}
},