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

[8.x] Add clean method to model #37756

Closed
wants to merge 1 commit into from
Closed

[8.x] Add clean method to model #37756

wants to merge 1 commit into from

Conversation

bernardwiesner
Copy link
Contributor

@bernardwiesner bernardwiesner commented Jun 21, 2021

Adds a clean method to models.

We already have isClean, so having a clean method on the model makes sense.

Examples:

$user = User::find(1);
$user->foo = 'bar';
$user->isClean(); // false
$user->clean();
$user->isClean(); // true

Use cases:

- Caching attributes

  1. Cache some query results on custom attribute on model.
  2. Re-use cached attribute throughout code. (if attribute not null, don't query DB)
  3. Want to clear cached attributes to re-query DB and re-cache.

- Cleaning model before updating

  1. Add custom attribute to model
  2. Use custom attribute throughout code
  3. Clean model
  4. Update some of models original attributes and save (this would fail without clean due to non existing column in DB)

@bernardwiesner bernardwiesner changed the title [8.x] Add clean method to model [8.x] Add clean method to model Jun 21, 2021
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

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.

2 participants