Level 60
https://laracasts.com/series/laravel-8-from-scratch
https://laravel.com/docs/9.x/eloquent-relationships
$students = Student::with('state')->get();
foreach ($student as $student) {
echo $student->state->name;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Let's assume, There Is two Table 'student' & 'state', 'student' table contain 'id', 'name', 'state_id'. and 'state' table contain 'id', 'state_name'. In 'student' table contain the corresponding State ID.
Now I want to fetch the student's details including the state name. (Note: In the student table, I contain only state id) How can I achieve this?
Please or to participate in this conversation.