> For the complete documentation index, see [llms.txt](https://mostafaznv.gitbook.io/larupload/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mostafaznv.gitbook.io/larupload/upload.md).

# Upload

There are three ways to upload files using Larupload:

* Upload by mutator
* Upload by the `attach` function
* Upload using the `create` method of the model

{% tabs %}
{% tab title="Mutator" %}
This is the easiest way to upload a file. You can upload a file by assigning the file to a property of your model.

It is advising that when uploading a file using Larupload, the corresponding property must be defined in the `attachments` method of the model.

```php
$upload = new Upload;
$upload->file = $request->file('file');
$upload->save();
```

{% endtab %}

{% tab title="Attach (IDE Friendly)" %}
With the `attach` function, you can upload both the file and its cover image (if applicable).

Here are the arguments that the `attach` function accepts:

* The first argument is the file that you want to upload (*required*).
* The second argument is the cover image for the file (*optional*).

```php
$file = $request->file('file');
$cover = $request->file('cover');
   
$upload->file->attach($file, $cover);
// or (recommended)
$upload->attachment('file')->attach($file, $cover);

$upload->save();
```

{% hint style="info" %}
If you provide a cover file when calling the `attach` function, the package will prioritize using your uploaded file as the cover instead of automatically generating one.
{% endhint %}
{% endtab %}

{% tab title="Create" %}
In this method, you can create and upload a file in one line of code. All you need to do is to pass the file and any required information to the `create` method of your model.

For example, if you have an `Upload` model that has an attachment named `file`, you can create and upload a file by writing the following code:<br>

```php
$upload = Upload::create([
    'file' => $request->file('file')
]);
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://mostafaznv.gitbook.io/larupload/upload.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
