Level 104
You are almost there:
// User.php
public function events()
{
return $this->belongsToMany('App\Event', 'registrations')->withPivot('registrationdate');
}
// Event.php
public function users() // you could make this more readable by naming it 'attendees'
{
return $this->belongsToMany('App\User', 'registrations');
}
// In your controller:
$user = User::find($id); // or Auth::user() ???
// Since you only want the active events, we need to get constrain the relationship:
$events = $user->events->filter(function($event)
{
return $event->active;
}
return view('name_of_view, compact('user', 'events'));
// In your view:
{!! $user->name !!}'s Events
@foreach($events as $event)
{!! $event->name !!}
{!! $event->registrationdate !!}
@endforeach