Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Allow custom pivot accessors #20411

Merged
merged 1 commit into from
Aug 4, 2017
Merged

[5.5] Allow custom pivot accessors #20411

merged 1 commit into from
Aug 4, 2017

Conversation

themsaid
Copy link
Member

@themsaid themsaid commented Aug 3, 2017

This adds the ability to define a belongsToMany relation like this:

public function podcasts()
{
    return $this->belongsToMany(Podcast::class, 'users_podcasts', 'user_id', 'podcast_id')
        ->as('subscription');
}

Now you'll be able to access the pivot data using $podcast->subscription instead of $podcast->pivot.

@ntzm
Copy link
Contributor

ntzm commented Aug 3, 2017

Never knew I wanted this until now, nice one 👍

@antonkomarev
Copy link
Contributor

Thank you for such great addition!

@taylorotwell taylorotwell merged commit e2ebd5b into laravel:master Aug 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants