Skip to content

[9.x] Adds handlers for silently discarded and missing attribute violations#44664

Merged
taylorotwell merged 3 commits into
laravel:9.xfrom
aarondfrancis:feat/strict-callbacks
Oct 20, 2022
Merged

[9.x] Adds handlers for silently discarded and missing attribute violations#44664
taylorotwell merged 3 commits into
laravel:9.xfrom
aarondfrancis:feat/strict-callbacks

Conversation

@aarondfrancis

Copy link
Copy Markdown
Contributor

This PR adds the ability to register handlers for two of the strict mode violations: silently discarded and missing attributes.

This ability is currently available for only the lazy load violations, this PR basically replicates that behavior for the other 2/3rds of Eloquent's new strict mode.

I think this will make it easier to adopt strict mode, as people can enable strict mode in production, but instead of throwing violations, they can log them.

@deKuddus

Copy link
Copy Markdown

@aarondfrancis, maybe this is going to be a good feature but did you see that a lots of changes are showing just due to changes of a single space. I think it was happened due to IDE configuration, so that this type of unnecessary changes are showing. Could you please recheck the changes again please??

@aarondfrancis

Copy link
Copy Markdown
Contributor Author

Fixed. I kinda thought that would happen automatically, which is why I left it. Thanks @deKuddus.

And thanks to @timacdonald for this incredible tip on how to fix this!

* @param callable|null $callback
* @return void
*/
public static function handleDiscardedAttributeViolationUsing(?callable $callback)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey
What scenario users might be required to call handleDiscardedAttributeViolationUsing(null); ?
Same for handleMissingAttributeViolationUsing(null) case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first thought would be during tests, to either enable or disable it dynamically. Not sure if that was the intended use-case.

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.

5 participants