Support the ongoing development of Laravel.io →
posted 8 years ago
Eloquent
Last updated 1 year ago.
0
Solution
$role = 'participants';
Event::query()->with(array('users'=>function($q) use ($role){
$q->withRole($role);
};
))->get();

Or you could create a relation that directly uses this scope:

Event::query()->with('participants')->get();

In Event class:


public function participants(){
return $this->users()->withRole('participants');
}
Last updated 8 years ago.
0

Nice, it works. This returns an Event with an array of participants. I was thinking, if I could get the participants without the Event.

For example: Give me all the participants from the Event 1.

Thank you!

Edit

I did it :D thank you so much for help!

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

FelipeReis felipereis Joined 20 Nov 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.