I am trying to build a query scope, but I can't get it to work. I get the following exception "Call to undefined method". The strange thing is the same query directly used on event works. Maybe someone can help me out.
$event->eventParticipantUser($participant)
public function scopeEventParticipantUser($query, EventParticipant $participant)
{
return $query->event_participants()->firstWhere('event_participant_id', $participant->id);
}
The query scope should be used before the eloquent model is being returned, so that's why you are getting that error, because you are trying to access it as a method on the model. The query scope, given the name is being added on the query builder, that's why you need to follow a convention being prefix the method with scope .