App\Traits\SupportsDeleteWhereIDsNotIn::deleteByChunk PHP Méthode

deleteByChunk() public static méthode

Delete records chunk by chunk.
public static deleteByChunk ( array $ids, string $key = 'id', integer $chunkSize = 65535 )
$ids array The array of record IDs to delete
$key string Name of the primary key
$chunkSize integer Size of each chunk. Defaults to 2^16-1 (65535)
    public static function deleteByChunk(array $ids, $key = 'id', $chunkSize = 65535)
    {
        DB::beginTransaction();
        try {
            foreach (array_chunk($ids, 65535) as $chunk) {
                static::whereIn($key, $chunk)->delete();
            }
            DB::commit();
        } catch (Exception $e) {
            DB::rollBack();
        }
    }
SupportsDeleteWhereIDsNotIn