App\Traits\SupportsDeleteWhereIDsNotIn::deleteWhereIDsNotIn PHP Метод

deleteWhereIDsNotIn() публичный статический Метод

Deletes all records whose IDs are not in an array.
public static deleteWhereIDsNotIn ( array $ids, string $key = 'id' ) : mixed
$ids array The array of IDs.
$key string Name of the primary key.
Результат mixed
    public static function deleteWhereIDsNotIn(array $ids, $key = 'id')
    {
        // If the number of entries is lower than, or equals to 65535, just go ahead.
        if (count($ids) <= 65535) {
            return static::whereNotIn($key, $ids)->delete();
        }
        // Otherwise, we get the actual IDs that should be deleted…
        $allIDs = static::select($key)->get()->pluck($key)->all();
        $whereInIDs = array_diff($allIDs, $ids);
        // …and see if we can delete them instead.
        if (count($whereInIDs) < 65535) {
            return static::whereIn($key, $whereInIDs)->delete();
        }
        // If that's not possible (i.e. this array has more than 65535 elements, too)
        // then we'll delete chunk by chunk.
        return static::deleteByChunk($ids, $key);
    }
SupportsDeleteWhereIDsNotIn