Improvement :
class Party extends Eloquent {
public function players()
{
$relation = $this->belongsToMany('User')->withPivot('registration_status_id');
$players = $relation->get();
foreach($players as &$p) {
$p->registration_status = RegistrationStatus::find( (int) $p->pivot->registration_status_id );
}
return $players;
}
}
but function still returns a collection, not a Relation object. So still can't use Party::find(2)->players[0]->registration_status->name; but Party::find(2)->players()[0]->registration_status->name
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community