-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[12.x] isSoftDeletable(), isPrunable(), and isMassPrunable() to model class #56060
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
Conversation
*/ | ||
protected function isPrunable(): bool | ||
{ | ||
return in_array(Prunable::class, class_uses_recursive(static::class)) || static::isMassPrunable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: It would be great if there were a ClassUsesRecursive once helper that would store these values for the lifetime of a request.
Written out as you have here, we can see that we're going to loop through all the traits of the class and its parent-classes twice if the class is MassPrunable but not Prunable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point 👍🏻 I had a similar idea—looks like there's an appetite for this 🚀
Co-authored-by: Luke Kuzmish <[email protected]> See laravel#55274 See laravel#56060 (comment)
… class (#56060) * feat(database): ✨ Add isSoftDeletable(), isPrunable(), and isMassPrunable() to model class * fix(database): 🐛 Call model method instead of command method * Restore "only check for soft deletes once when mass-pruning" Co-authored-by: Luke Kuzmish <[email protected]> See laravel/framework#55274 See laravel/framework#56060 (comment) * Fix typo Follow-up to 07520f2225a78a183c6d02da11f662ddf207657d * formatting * fix test --------- Co-authored-by: Taylor Otwell <[email protected]>
… class (#56060) * feat(database): ✨ Add isSoftDeletable(), isPrunable(), and isMassPrunable() to model class * fix(database): 🐛 Call model method instead of command method * Restore "only check for soft deletes once when mass-pruning" Co-authored-by: Luke Kuzmish <[email protected]> See laravel/framework#55274 See laravel/framework#56060 (comment) * Fix typo Follow-up to 07520f2225a78a183c6d02da11f662ddf207657d * formatting * fix test --------- Co-authored-by: Taylor Otwell <[email protected]>
Before
After
Benefits
✅ Encapsulated implementation details: Unrelated places don't need to concern themselves with how it's done
✅ Single source of truth: Now easily refactorable, only one place needs to be changed
✅ DRY
Alternatives