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

UpdateOrCreate #817

Closed
1 task done
BSN4 opened this issue Oct 18, 2022 · 4 comments
Closed
1 task done

UpdateOrCreate #817

BSN4 opened this issue Oct 18, 2022 · 4 comments
Labels
enhancement A feature that exists, works as intended but needs to be improved feature request A feature that does not yet exist but will be a good addition to the library

Comments

@BSN4
Copy link
Contributor

BSN4 commented Oct 18, 2022

Describe the feature as you'd like to see it
Some time you want either to update existing raw or create it .. awesome to have UpdateOrCreate

What do we currently have to do now?
https://laravel.com/docs/9.x/upgrade#belongs-to-many-first-or-new

  • I don't think it will be breaking change
@BSN4 BSN4 added enhancement A feature that exists, works as intended but needs to be improved feature request A feature that does not yet exist but will be a good addition to the library labels Oct 18, 2022
@Marlysson
Copy link
Contributor

@josephmancuso @girardinsamuel

There's the model.update_or_create method, but it receives the wheres and the values to update, when replicate the example of link in laravel docs it becomes:

user.related("roles").update_or_create(wheres, updates)

The "wheres" argument, Isn't relation when called, redundant?

@BSN4
Copy link
Contributor Author

BSN4 commented Oct 19, 2022

@Marlysson thanks didn't find it in the docs

@BSN4 BSN4 closed this as completed Oct 19, 2022
@BSN4
Copy link
Contributor Author

BSN4 commented Oct 19, 2022

@Marlysson can it be used outside relations though? like Order.update_or_create({})

@josephmancuso
Copy link
Member

@Marlysson can it be used outside relations though? like Order.update_or_create({})

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature that exists, works as intended but needs to be improved feature request A feature that does not yet exist but will be a good addition to the library
Projects
None yet
Development

No branches or pull requests

3 participants