laravel 4 - When using "find" on relation it gives me the pivot id -
i have organization model , when try retrieve specific user organization gives me user, id on user object pivot-id many-to-many relation table.
class organization extends eloquent { public function users() { return $this->belongstomany('user', 'organizations_users', "organization_id" ,"user_id"); } }
and user model
class user extends eloquent implements userinterface, remindableinterface { use remindabletrait; protected $table = 'users'; protected $hidden = array('password'); protected $fillable = array('email', 'password'); public function organizations() { return $this->belongstomany('organization', 'organizations_users'); } }
but when retrieve specific organizations users method
$org = organization::find(12); $org->users()->find(4);
it returns pivot-table id on user-object instead of users own id.
"id" => 74 "first_name" => "thomas" "last_name" => "bolander" .... "organization_id" => 12 "user_id" => 4 ....
this works
$org = organization::find(12); $org->users()->where("users.id",4)->first();
anybody have idea whats wrong here ?
hey thomas can try too
$org->users()->getrelated()->find(4);
Comments
Post a Comment