# Preserve Files

The `preserveFiles` function on the `Attachment` is used to enable or disable the preservation of files when `deleting` a record. When this function is enabled, Larupload will not delete the files associated with a record even when the record is deleted from the database. This can be useful in situations where you want to keep the files for some other purpose, even after the associated record has been deleted. By default, `preserveFiles` is set to `false` which means that files will be deleted when the associated record is deleted from the database.

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mostafaznv\Larupload\Storage\Attachment;
use Mostafaznv\Larupload\Traits\Larupload;

class Media extends Model
{
    use Larupload;

    public function attachments(): array
    {
        return [
            Attachment::make('file')->preserveFiles(true)
        ];
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mostafaznv.gitbook.io/larupload/advanced-usage/attachment/preserve-files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
