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

DDSameera's avatar

3 table Eloquent Query Build up

User Model

   public function courses()
    {
        return $this->belongsToMany(Course::class);
    }

    public function meetings()
    {
        return $this->belongsToMany(Meeting::class)->withPivot('unique_join_url');
    }

Meeting Model

public function users()
    {
        return $this->belongsToMany(User::class)->withPivot('unique_join_url');
    }

Course Model


    public function users()
    {
        return $this->belongsToMany(User::class);
    }

    public function meeting(){
        return $this->belongsTo(Meeting::class,'meeting_id','id');

    }

I want to get Logged user's course meeting URL (Zoom Meeting URL)

Could you please help me ? to build up query in controller.

0 likes
3 replies
tisuchi's avatar

@ddsameera I am wondering why you define everything belongsToMany()?

BTW, since it has many relationships, it will be hard to get any specific courses->meeting directly. You have to use a loop to get any specific records.

DDSameera's avatar

That is the nature of this project Sorry.

DDSameera's avatar
DDSameera
OP
Best Answer
Level 3

@tisuchi i created it by my self

  $courseId = "1";
        $course = Course::with('meeting')->get()->find($courseId);
        $meetingUser = $course->meeting->users->first();
        $uniqueJoinUrl = $meetingUser->pivot->unique_join_url;

Please or to participate in this conversation.