Level 104
Model instances need a key.
When using this feature, you should always include the id column in the list of columns you wish to retrieve.
https://laravel.com/docs/5.6/eloquent-relationships#eager-loading
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have this query below to get the conference associated with the Registration.
Do you know why 'id' is necessary? Is because is the primary key of the conferences table and the foreign key in the registrations table? Even that in the registrations table this foreign key has the name "conference_id" and not just "id".
$registration = Registration::with([
'conference' => function ($query) {
$query->select('id', 'name', 'address');
}
])->find($regID);
Model instances need a key.
When using this feature, you should always include the id column in the list of columns you wish to retrieve.
https://laravel.com/docs/5.6/eloquent-relationships#eager-loading
Please or to participate in this conversation.