erdely said:
I have following tables:
- users (classic laravel table)
- events
- user_events
// event model
public function userEvents()
{
return $this->hasMany('App\Models\UserEvent');
}
// user event model
public function user()
{
return $this->belongsTo('App\Models\User');
}
public function event()
{
return $this->belongsTo('App\Models\Event');
}
// example of resultset
$user_events = UserEvent:get();
foreach ($user_events as $user_event)
{
echo $user_event->user->name; // displays the user's name that is associated with user_event
echo $user_event->event->name; // displays the even'ts name that is associated with user_event
}
hope that helps
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community