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

sync with pivot automatically #23402

Closed
ChitaGideon opened this issue Mar 6, 2018 · 2 comments
Closed

sync with pivot automatically #23402

ChitaGideon opened this issue Mar 6, 2018 · 2 comments

Comments

@ChitaGideon
Copy link

  • Laravel Version: 5.5.*
  • PHP Version:7.0
  • Database Driver & Version:mysql

Description:

define a relations with pivot like:

    public function foods()
    {
        return $this->morphToMany('App\Models\FoodInfo', 'fooddables')->wherePivot('type', 1);
    }

When I try to sync this relation,pivot column can not be update automatically .

$relation->sync([1,2,3]);//can not update type

$relation->sync([1=>['type'=>1],2=>['type'=>1],3=>['type'=>1],]);//can be work

Steps To Reproduce:

@devcircus
Copy link
Contributor

Look at #22867. Does that solve your issue?

So try changing foods() to:

    public function foods()
    {
        return $this->morphToMany('App\Models\FoodInfo', 'fooddables')->withPivotValues('type', 1);
    }

@ChitaGideon
Copy link
Author

@devcircus
thanks for your reply;
From that example in #22867 , It looks like the right answer if attach method works in the same way as sync works .
If I want to use this , I have to update to 5.6 version of laravel ?

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

No branches or pull requests

3 participants