I'm not sure I understand. How do you want to compare it?
Comparing Pivot Table record with current logged in user
I am trying to implement a general events module. I have 3 tables:
- Users
- Events
- 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:
-
If user has already enrolled in an event he will see "Already Enrolled"
-
Then if he has not enrolled he will see "Enroll Now"
-
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.
Please or to participate in this conversation.