Support the ongoing development of →
Database Eloquent Architecture
Last updated 2 years ago.

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

Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?

SebSept sebsept Joined 20 Feb 2014


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

Your logo here?

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

© 2024 - All rights reserved.