Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thomas.midhun1@gmail.com's avatar

how to access three models and get data

what I mean is how to access a specific database table with foreign key connected,like this way

        $user = auth()->guard(GuardType::STAFF)->user();

        $schedules = $user->business->staffmembers->staffschedules;

then we have all details about staff_schedules tables in $schedules. So please help me to make this.

0 likes
7 replies
wingly's avatar

You can use the load method $user->load('business.staffmembers.staffschedules')

thomas.midhun1@gmail.com's avatar

I try to use it but got following error.

Illuminate\Database\Eloquent\RelationNotFoundException Call to undefined relationship [staffschedules] on model [App\Models\BusinessStaffMember].

abhijeet9920's avatar

You have to define missing relations in appropriate models

Please or to participate in this conversation.