Skip to content

[12.x] Cache isSoftDeletable(), isPrunable(), and isMassPrunable() directly in model #56078

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

Open
wants to merge 3 commits into
base: 12.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ abstract class Model implements Arrayable, ArrayAccess, CanBeEscapedWhenCastToSt
*/
protected static string $collectionClass = Collection::class;

/**
* Whether it implements the SoftDeletes trait.
*/
protected static bool $isSoftDeletable;

/**
* Whether it implements the Prunable trait.
*/
protected static bool $isPrunable;

/**
* Whether it implements the MassPrunable trait.
*/
protected static bool $isMassPrunable;

/**
* The name of the "created at" column.
*
Expand Down Expand Up @@ -2294,23 +2309,23 @@ public function setPerPage($perPage)
*/
public static function isSoftDeletable(): bool
{
return in_array(SoftDeletes::class, class_uses_recursive(static::class));
return self::$isSoftDeletable ??= in_array(SoftDeletes::class, class_uses_recursive(static::class));
}

/**
* Determine if the model is prunable.
*/
protected function isPrunable(): bool
{
return in_array(Prunable::class, class_uses_recursive(static::class)) || static::isMassPrunable();
return self::$isPrunable ??= in_array(Prunable::class, class_uses_recursive(static::class)) || static::isMassPrunable();
}

/**
* Determine if the model is mass prunable.
*/
protected function isMassPrunable(): bool
{
return in_array(MassPrunable::class, class_uses_recursive(static::class));
return self::$isMassPrunable ??= in_array(MassPrunable::class, class_uses_recursive(static::class));
}

/**
Expand Down
Loading