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

Eloquent Update Method return model #13488

Closed
fernandobandeira opened this issue May 9, 2016 · 2 comments
Closed

Eloquent Update Method return model #13488

fernandobandeira opened this issue May 9, 2016 · 2 comments

Comments

@fernandobandeira
Copy link
Contributor

fernandobandeira commented May 9, 2016

Currently the update() method is returning the result of the save() (Boolean), on the other hand the create method is returning a model, shouldn't the update method also return a model?

This way the update method keeps the fluent interface, also for a rest app for the put method you could just:

return $model->update($request->all());

And the result would be a json of the updated model...

Is this worth changing?

@GrahamCampbell
Copy link
Member

No, sorry. It also returns false is there were no changes made, so the return value has meaning already.

@fernandobandeira
Copy link
Contributor Author

fernandobandeira commented May 9, 2016

@GrahamCampbell Actually it is returning true

Get on localhost:8000/client/1

{
  "id": 1,
  "name": "Ashly Lehner",
  "responsible": "Kristy Kuhn",
  "email": "tveum@example.com",
  "phone": "1-717-936-3681",
  "address": "2893 Deonte Inlet\nDevonberg, IL 38054",
  "obs": "Enim et eos voluptatem voluptas.",
  "created_at": "2016-05-09 12:48:13",
  "updated_at": "2016-05-09 12:48:13"
}

Content of the update() method:

Client::find($id)->update($request->all());

For an empty PUT request (nothing is gonna change) the result is true

For a PUT request with (name = current name):

name = Ashly Lehner

the result is also true

For a PUT request with (name != current name):

name = Ashly Lehn

the result is also true

I would expect to get a false on the empty PUT request and maybe a false when the request content is the same as the model content, both cases return true, it does return false if the model doesn't pass on a custom validation.

Maybe this behavior is not implemented yet?
Also couldn't it return a model on success? (how bad would this be?)

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

2 participants