Closed ntvsx193 closed 8 years ago
with
is to eagerLoad relationships and findOrFail
only work when intentionally fetching model instances. Here since you are going to load only 1 record, I would suggest to go this way.
let server = yield Server.findOrFail(id) // if error it fails early, instead of loading machine
// this line will load the related machine and it will add the result to the fetched instance
yield server.related('machine').load()
response.json(server)
Oh, yes, thank you! It'll be write in docs.
let server = yield Server.with('machine').findOrFail(id)
genarate 500 error.with(...).findOrFail is not a function
However, if i use some code as
yield Server.with('machine').fetch()
- response is ok.App/Http/Controllers/ServerController
:App/Model/Server
:App/Model/Machine