Try switching id and room_id, or remove them. I don't think you need to specify them since you're db is properly constructed.
return $this->hasOne('App\Room', 'id', 'room_id');
For a project of mine I'm trying to set up an API through Lumen. In this project I'm creating a website for a cinema. I chose Lumen as way of gettting an understanding of something new.
The database is structured as follows:

The relationships are: A movie can have many shows, and a show has one room
To get this data from the database through Lumen I have tried the following:
public function one($id) {
return response()->json(Movie::where('id', '=',$id)->with(['types','shows.room'])->first(), 200);
}
public function types() {
return $this->hasMany('App\Types', 'movie_id');
}
public function shows() {
return $this->hasMany('App\Show', 'movie_id');
}
public function movie() {
return $this->belongsTo('App\Movie');
}
public function room() {
return $this->hasOne('App\Room', 'id', 'room_id');
}
public function show() {
return $this->belongsTo('App\Show', 'room_id', 'id');
}
With a lot of googling, and a lot of tries, I have come to this point where it still does the same as it did when I tried it without googling it. It returns everything BUT the room data properly. The room data remains null
{
"id": 1,
"title": "Fast & Furious",
"desc": "Geregisseerd door James Wan met Vin Diesel, Jason Statham en Lucas Black\nNadat Dominic Toretto lucht krijgt van Han's dood, reist hij met zijn crew naar Tokyo, waar ze Sean Boswell ontmoeten, de driftkoning en een vriend van Han. Ze vormen een team met Sean en enkele nieuwe vrienden en gaan erop uit om hun gevallen vriend te wreken. Hierbij stuitten ze op de man die Han heeft vermoord, Ian Shaw, de oudere broer van Owen Shaw en leider van een geheime en illegale straatrace-organisatie.",
"genre": "Actie",
"duration": 122,
"age": "16",
"price": 9.75,
"status": "upcoming",
"poster": "https://image.tmdb.org/t/p/original/b9gTJKLdSbwcQRKzmqMq3dMfRwI.jpg",
"backdrop": "https://image.tmdb.org/t/p/original/qjfE7SkPXpqFs8FX8rIaG6eO2aK.jpg",
"created_at": "2018-06-19 14:18:57",
"updated_at": "2018-06-19 14:18:57",
"types": [
{
"type": "IMAX",
"created_at": "2018-06-19 14:18:57",
"updated_at": "2018-06-19 14:18:57"
},
{
"type": "4DX",
"created_at": "2018-06-19 14:18:57",
"updated_at": "2018-06-19 14:18:57"
}
],
"shows": [
{
"id": 1,
"room_id": 1,
"movie_id": 1,
"date": "2015-04-16",
"time": "16:30:00",
"created_at": "2018-06-19 14:18:57",
"updated_at": "2018-06-19 14:18:57",
"room": null
},
{
"id": 2,
"room_id": 1,
"movie_id": 1,
"date": "2015-04-16",
"time": "20:30:00",
"created_at": "2018-06-19 14:18:57",
"updated_at": "2018-06-19 14:18:57",
"room": null
}
]
}
I hope you can help me
Please or to participate in this conversation.