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

asad89's avatar

Comparing Pivot Table record with current logged in user

I am trying to implement a general events module. I have 3 tables:

  1. Users
  2. Events
  3. event_user (Pivot table)

Structure of users table

id, name, email, etc

Structure of Events table

id, name, created_at, updated_at

Structure of my pivot table, two additional columns are there

id, user_id, event_id, membership_type, status

Now in my User model i can get the events of user as:

public function events() { return $this->belongsToMany(Event::class)->withPivot(['membership_type','status'])->withTimestamps(); }

On Events page i will list all the events.

On each event there will be a button for logged in user to work as:

  1. If user has already enrolled in an event he will see "Already Enrolled"

  2. Then if he has not enrolled he will see "Enroll Now"

  3. If he has "enrolled by status in pivot table is pending" He will see "you have enrolled but it need confirmation"

I am confused how i can compare the events with logged in user, I will highly appreciate the suggestions.

0 likes
2 replies
bugsysha's avatar

I'm not sure I understand. How do you want to compare it?

1 like
asad89's avatar

Thank you for your response. When i will be listing all events for the user how i can check if user has already enrolled in the event that was my question.

Please or to participate in this conversation.