{"id":36976338,"url":"https://github.com/nadlambino/laravel-uploadable","last_synced_at":"2026-01-13T22:12:42.621Z","repository":{"id":264517658,"uuid":"822456297","full_name":"nadlambino/laravel-uploadable","owner":"nadlambino","description":"Automatically handle the file uploads for your models.","archived":false,"fork":false,"pushed_at":"2025-02-13T18:47:59.000Z","size":147,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-03T19:59:42.195Z","etag":null,"topics":["file-uploads","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nadlambino.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"NadLambino"}},"created_at":"2024-07-01T07:31:52.000Z","updated_at":"2025-02-22T03:08:38.000Z","dependencies_parsed_at":"2024-11-24T20:34:08.312Z","dependency_job_id":"63ec330c-3145-4f5f-85f4-7eac77571d31","html_url":"https://github.com/nadlambino/laravel-uploadable","commit_stats":null,"previous_names":["nadlambino/laravel-uploadable"],"tags_count":5,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/nadlambino/laravel-uploadable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadlambino%2Flaravel-uploadable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadlambino%2Flaravel-uploadable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadlambino%2Flaravel-uploadable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadlambino%2Flaravel-uploadable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nadlambino","download_url":"https://codeload.github.com/nadlambino/laravel-uploadable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadlambino%2Flaravel-uploadable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28402633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file-uploads","laravel","php"],"created_at":"2026-01-13T22:12:41.913Z","updated_at":"2026-01-13T22:12:42.614Z","avatar_url":"https://github.com/nadlambino.png","language":"PHP","funding_links":["https://github.com/sponsors/NadLambino"],"categories":[],"sub_categories":[],"readme":"# Automatically handle the file uploads for your models.\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/nadlambino/uploadable.svg?style=flat-square)](https://packagist.org/packages/nadlambino/uploadable)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/nadlambino/uploadable/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/nadlambino/uploadable/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/nadlambino/uploadable/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/nadlambino/uploadable/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/nadlambino/uploadable.svg?style=flat-square)](https://packagist.org/packages/nadlambino/uploadable)\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Customization](#customization)\n- [Manually Processing of File Uploads](#manually-processing-of-file-uploads)\n- [Temporarily Disable the File Uploads](#temporarily-disable-the-file-uploads)\n- [Uploading Files on Model Update](#uploading-files-on-model-update)\n- [Uploading Files that are NOT from the Request](#uploading-files-that-are-not-from-the-request)\n- [Relation Methods](#relation-methods)\n- [Lifecycle and Events](#lifecycle-and-events)\n- [Queueing](#queueing)\n- [Testing](#testing)\n- [Changelog](#changelog)\n- [Contributing](#contributing)\n- [Security Vulnerabilities](#security-vulnerabilities)\n- [Credits](#credits)\n- [License](#license)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require nadlambino/uploadable\n```\n\nPublish and run the migrations with:\n\n```bash\nphp artisan vendor:publish --tag=\"uploadable-migrations\"\nphp artisan migrate\n```\n\u003e [!IMPORTANT]\n\u003e \n\u003e You can add more fields to the uploads table according to your needs, but the existing fields should remain.\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"uploadable-config\"\n```\n\nThis is the contents of the published config file:\n\n\u003cdetails\u003e\n    \u003csummary\u003euploadable.php\u003c/summary\u003e\n\n```php\nreturn [\n\n    /*\n    |--------------------------------------------------------------------------\n    | Validation\n    |--------------------------------------------------------------------------\n    |\n    | Enable or disable the package's validation rules. Set to false if validation\n    | has been performed separately, such as in a form request.\n    |\n    */\n    'validate' =\u003e true,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Uploads Model\n    |--------------------------------------------------------------------------\n    |\n    | Specify the model to use for uploads.\n    |\n    */\n    'uploads_model' =\u003e \\NadLambino\\Uploadable\\Models\\Upload::class,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Delete Model on Upload Failure\n    |--------------------------------------------------------------------------\n    |\n    | Automatically delete the newly created model if the upload process fails.\n    | Applicable only to models that are being created.\n    |\n    */\n    'delete_model_on_upload_fail' =\u003e true,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Rollback Model on Upload Failure\n    |--------------------------------------------------------------------------\n    |\n    | Revert changes made to an existing model if the upload fails, restoring\n    | the model's original attributes. Applies only to updated models.\n    |\n    */\n    'rollback_model_on_upload_fail' =\u003e true,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Force Delete Uploads\n    |--------------------------------------------------------------------------\n    |\n    | Determines whether uploaded files are permanently deleted. By default,\n    | files are soft deleted, allowing for recovery.\n    |\n    */\n    'force_delete_uploads' =\u003e false,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Replace Previous Uploads\n    |--------------------------------------------------------------------------\n    |\n    | Determines whether uploaded files should be replaced with new ones. If\n    | false, new files will be uploaded. If true, previous files will be\n    | deleted once the new ones are uploaded.\n    |\n    */\n    'replace_previous_uploads' =\u003e false,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Upload Queue\n    |--------------------------------------------------------------------------\n    |\n    | Specify the queue name for uploading files. If set to null, uploads are\n    | processed immediately. Otherwise, files are queued and processed.\n    |\n    */\n    'upload_on_queue' =\u003e null,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Delete Model on Queued Upload Failure\n    |--------------------------------------------------------------------------\n    |\n    | Delete the newly created model if a queued upload fails. Only affects models\n    | that are being created.\n    |\n    */\n    'delete_model_on_queue_upload_fail' =\u003e false,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Rollback Model on Queued Upload Failure\n    |--------------------------------------------------------------------------\n    |\n    | Revert changes to a model if a queued upload fails, using the model's original\n    | attributes before the upload started. Affects only updated models.\n    |\n    */\n    'rollback_model_on_queue_upload_fail' =\u003e false,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Temporary Storage Disk\n    |--------------------------------------------------------------------------\n    |\n    | Define the disk for temporary file storage during queued uploads. This\n    | is where files are stored before being processed.\n    |\n    */\n    'temporary_disk' =\u003e 'local',\n\n    /*\n    |--------------------------------------------------------------------------\n    | Temporary URL\n    |--------------------------------------------------------------------------\n    |\n    | Temporary URL for files that are uploaded locally is not supported by the\n    | local disk. This setting allows you to specify the path and middleware to\n    | access the files temporarily which uses a signed URL under the hood.\n    | `expiration` can be a string or an instance of `DateTimeInterface`.\n    |\n    */\n    'temporary_url' =\u003e [\n        'path' =\u003e '/temporary',\n        'middleware' =\u003e ['signed'],\n        'expiration' =\u003e '1 hour',\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Allowed Mimes by Extension\n    |--------------------------------------------------------------------------\n    |\n    | Specify the mime types by extension that is allowed for uploads. Supports\n    | categorization for images, videos, and documents with specific file\n    | extensions.\n    |\n    */\n    'mimes' =\u003e [\n        'image' =\u003e ['jpeg', 'jpg', 'png', 'gif', 'bmp', 'svg', 'webp', 'ico'],\n        'video' =\u003e ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', '3gp', 'mkv', 'mpg', 'mpeg'],\n        'document' =\u003e ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'csv', 'txt'],\n    ],\n];\n```\n\u003c/details\u003e\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Usage\n\nSimply use the `NadLambino\\Uploadable\\Concerns\\Uploadable` trait to your model that needs file uploads.\n\n```php\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse NadLambino\\Uploadable\\Concerns\\Uploadable;\n\nclass Post extends Model\n{\n    use Uploadable;\n}\n```\n\nNow, everytime you create or update a post, it will automatically upload the files that are included in your request and it will save the details in `uploads` table.\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Customization\n\n### 1. Rules and Messages\n\nFiles from the request should have the following request names:\n\n| Request name | Use Case                  | Rules                  |\n|--------------|---------------------------|------------------------|\n| document     | Single document upload    | sometimes, file, mime  |\n| documents    | Multiple document uploads | sometimes, file, mime  |\n| image        | Single image upload       | sometimes, image, mime |\n| images       | Multiple image uploads    | sometimes, image, mime |\n| video        | Single video upload       | sometimes, mime        |\n| videos       | Multiple video uploads    | sometimes, mime        |\n\nYou can add more fields or override the default ones by defining the protected `uploadRules`\nmethod in your model.\n\n```php\nprotected function uploadRules(): array\n{\n    return [\n        // Override the rules for `document` field\n        'document' =\u003e ['required', 'file', 'mime:application/pdf'], \n\n        // Add a new field with it's own set of rules\n        'avatar' =\u003e ['required', 'image', 'mime:png'] \n    ];\n}\n```\n\nTo add or override the rules messages, you can define the protected `uploadRuleMessages` method in your model.\n\n```php\npublic function uploadRuleMessages(): array\n{\n    return [\n        'document.required' =\u003e 'The file is required.',\n        'document.mime' =\u003e 'The file must be a PDF file.',\n        'avatar.required' =\u003e 'The avatar is required.',\n        'avatar.mime' =\u003e 'The avatar must be a PNG file.'\n    ];\n}\n```\n\n### 2. File Name and Upload Path\n\nYou can customize the file name and path by defining the public methods `getUploadFilename` and `getUploadPath` in your model.\n\n```php\npublic function getUploadFilename(UploadedFile $file): string\n{\n    return str_replace('.', '', microtime(true)).'-'.$file-\u003ehashName();\n}\n\npublic function getUploadPath(UploadedFile $file): string\n{\n    return $this-\u003egetTable().DIRECTORY_SEPARATOR.$this-\u003e{$this-\u003egetKeyName()};\n}\n```\n\n\u003e [!IMPORTANT]\n\u003e \n\u003e Make sure that the file name is completely unique to avoid overriding existing files.\n\n### 3. Storage Options\n\nWhen you're uploading your files on cloud storage, oftentimes you want to provide options like visibility, cache control, and other metadata. To do so, you can define the `getUploadStorageOptions` in your model.\n\n```php\npublic function getUploadStorageOptions(): array\n{\n    return [\n        'visibility' =\u003e 'public',\n        'CacheControl' =\u003e 'max-age=315360000, no-transform, public'\n    ];\n}\n```\n\n### 4. Upload Disk\n\nWhen you're uploading your files, sometimes you just upload it on your local disk. However for larger files, you may want to use `s3`. This can be with static method `uploadDisk`.\n\n```php\n// Let us say that on your config/filesystems.php, your default disk is set to `local`.\n// This method will create a user and will upload the file from the request, e.g., user avatar.\npublic function store(Request $request)\n{\n    User::create(...);\n}\n\n// While this method store the message and will upload the file from the request to `s3`.\npublic function store(Request $request)\n{\n    Message::uploadDisk('s3');\n    Message::create(...);\n}\n```\n\n### 5. Grouping of Uploads\n\nWhen uploading a files for your model, sometimes you can have multiple file uploads for different purposes. For example, a post could have a file upload for thumbnail, banners, and gallery. This can be achieve with `uploadToCollection` method.\n\n```php\npublic function store(Request $request)\n{\n    Post::uploadToCollection('banner');\n\n    Post::create(...);\n}\n```\n\nAlso, to retrieve file uploads of specific collection, you can use the scope query `fromCollection`.\n\n```php\n$post = Post::query()\n    -\u003ewith('image', fn ($query) =\u003e $query-\u003efromCollection('banner'))\n    -\u003efind(...);\n```\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Manually Processing of File Uploads\n\nFile upload happens when the model's `created` or `updated` event was fired.\nIf you're creating or updating a model quietly, you can call the `createUploads` or `updateUploads` method to manually process the file uploads.\n\n```php\npublic function update(Request $request, Post $post)\n{\n    $post-\u003eupdate($request-\u003eall());\n    \n    // If the post did not change, the `updated` event won't be fired.\n    // So, we need to manually call the `updateUploads` method.\n    if (! $post-\u003ewasChanged()) {\n        $post-\u003eupdateUploads();\n    }\n}\n```\n\u003e [!IMPORTANT]\n\u003e \n\u003e Depending on your configuration, the `createUploads` will delete the model when the upload process fails, while `updateUploads` will update it to its original attributes.\n\n## Temporarily Disable the File Uploads\n\nYou can temporarily disable the file uploads by calling the static method `disableUpload`.\n\n```php\npublic function update(Request $request, Post $post)\n{\n    // Temporarily disable the file uploads\n    Post::disableUpload();\n    \n    $post-\u003eupdate($request-\u003eall());\n    \n    // Do more stuff here...\n    \n    // Manually process the uploads after everything you want to do\n    $post-\u003eupdateUploads();\n}\n```\n\n### Caveat\n\nWhen you are trying to create or update multiple models, the default behavior is that all of the files from the request will be uploaded and will be attached to all of these models. This is because these models are firing the `created` or `updated` event which triggers the upload process. \n\nThere are multiple ways to prevent this from happening such as:\n\n- Silently create or update the models. By doing so, the `created` or `updated` event won't be fired which will not trigger the upload process. This may not be what you want if you have a model observer for these two events.\n- Disable the upload process on the specific model by calling the `disableUpload()` method.\n- Disable the upload process from the `NadLambino\\Uploadable\\Actions\\Upload` action itself. The `Upload::disableFor()` method can accept a model class name, a model instance, or an array of each or both. See below example:\n\n```php\nuse NadLambino\\Uploadable\\Actions\\Upload;\n\npublic function store(Request $request)\n{\n    // Disable the uploads for all of the instances of Post model\n    Upload::disableFor(Post::class);\n\n    // Files will be uploaded for User model\n    User::create(...);\n\n    // Files won't be uploaded for Post model\n    Post::create(...);\n}\n\n// OR\n\npublic function update(Request $request, User $user)\n{\n     // Disable the uploads only for this specific $user\n    Upload::disableFor($user);\n\n    // Files won't be uploaded for this specific $user\n    $user-\u003eupdate($request-\u003evalidated());\n    \n    $anotherUser = User::find(...);\n\n    // Files will be uploaded for this $anotherUser\n    $anotherUser-\u003eupdate(...);\n}\n```\n\n- Lastly, specifically instruct the `NadLambino\\Uploadable\\Actions\\Upload` to process the upload only for the specific given model by calling the `Upload::onlyFor` method. This method has the same parameter signature as `Upload::disableFor` and ensure that only these given model classes or instances will be process.\n\n```php\nuse NadLambino\\Uploadable\\Actions\\Upload;\n\npublic function store()\n{\n    // Process the uploads only for all of the instances of User model\n    Upload::onlyFor(User::class);\n\n    // Files will be uploaded for this User model\n    User::create(...);\n\n    // Files won't be uploaded for this Post model\n    Post::create(...);\n}\n\npublic function update(User $user)\n{\n    // Process the uploads only for this specific $user\n    Upload::onlyFor($user);\n\n    // Files will be uploaded for this specific $user\n    $user-\u003eupdate(...);\n\n    $anotherUser = User::find(...);\n\n    // Files won't be uploaded for this $anotherUser\n    $anotherUser-\u003eupdate(...)\n}\n```\n\nAlso, there is `NadLambino\\Uploadable\\Actions\\Upload::enableFor()` method if you need to delist a model from the disabled list. It is different from `onlyFor` in a way that `onlyFor` method ensures that the files were only be uploaded to the given models while `enableFor` just simply removes the given models from the disabled list.\n\nAll of these methods could also work even when you are uploading on a queue.\n\n\u003e [!NOTE]\n\u003e\n\u003e When calling the `disableFor` method, it will remove the given model from the list of `onlyFor` models. Same goes when calling the `onlyFor` method, it will remove the given model from the list of disabled models.\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Uploading files on model update\n\nBy default, when you update a model, the files from the request will add up to the existing uploaded files. If you want to replace the existing files with the new ones, you can configure it in the `uploadable.php` config file.\n\n```php\n'replace_previous_uploads' =\u003e true,\n```\n\nOr alternatively, you can call the static method `replacePreviousUploads` before updating the model.\n\n```php\npublic function update(Request $request, Post $post)\n{\n    // Replace the previous uploads\n    Post::replacePreviousUploads();\n\n    $post-\u003eupdate($request-\u003eall());\n}\n```\n\n\u003e [!NOTE]\n\u003e \n\u003e The process of deleting the previous uploads will only happen when new files were successfully\n\u003e uploaded.\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Uploading files that are NOT from the request\n\nIf you wish to upload a file that is NOT directly from the request, you can do so by calling the `uploadFrom` method. This method can accept an instance or an array of `Illuminate\\Http\\UploadedFile` or a string path of a file that is uploaded on your `temporary_disk`.\n\n```php\n// DO\n$post-\u003euploadFrom($request-\u003efile('image'));\n\n// OR\n$post-\u003euploadFrom(new UploadedFile(...));\n\n// OR\n$post-\u003euploadFrom([\n    $request-\u003efile('image'),\n    $request-\u003efile('avatar')\n]);\n\n// OR\n$fullpath = ... // The path of the file that is uploaded in your `temporary_disk`. This could be something like an image that was modified by `ImageIntervention` then temporarily stored before uploading\n\n$post-\u003euploadFrom($fullpath);\n\n// OR\n$post-\u003euploadFrom([\n    $fullpath1,\n    $fullpath2\n]);\n\n// OR even a mixed of both\n$post-\u003euploadFrom([\n    $request-\u003efile('image'),\n    $fullpath,\n]);\n\n$post-\u003esave();\n```\n\n\u003e [!IMPORTANT]\n\u003e \n\u003e Make sure that you've already validated the files that you're passing here as it does not run any validation like it does when uploading directly from the request.\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Relation methods\n\nThere are already pre-defined relation method for specific upload type.\n\n```php\n// Relation for all types of uploads\npublic function upload(): MorphOne { }\n\n// Relation for all types of uploads\npublic function uploads(): MorphMany { }\n\n// Relation for uploads where extension or type is in the accepted image mimes\npublic function image(): MorphOne { }\n\n// Relation for uploads where extension or type is in the accepted image mimes\npublic function images(): MorphMany { }\n\n// Relation for uploads where extension or type is in the accepted video mimes\npublic function video(): MorphOne { }\n\n// Relation for uploads where extension or type is in the accepted video mimes\npublic function videos(): MorphMany { }\n\n// Relation for uploads where extension or type is in the accepted document mimes\npublic function document(): MorphOne { }\n\n// Relation for uploads where extension or type is in the accepted document mimes\npublic function documents(): MorphMany { }\n```\n\n\u003e [!IMPORTANT]\n\u003e \n\u003e MorphOne relation method sets a limit of one in the query.\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Lifecycle and Events\n\nDuring the entire process of uploading your files, events are being fired in each step. This comes very helpful if you need to do something in between these steps or just for debugging purposes.\n\n| Event                                              | When It Is Fired                       | What The Event Receives When Dispatched |\n|----------------------------------------------------|----------------------------------------|-----------------------------------------|\n| `NadLambino\\Uploadable\\Events\\BeforeUpload::class` | Fired before the upload process starts | `Model $uploadable`, `array $files`, `UploadOptions $options` |\n| `NadLambino\\Uploadable\\Events\\StartUpload::class`  | Fired when the upload process has started and its about to upload the first file in the list. This event may fired up multiple times depending on the number of files that is being uploaded | `Model $uploadable`, `string $filename`, `string $path` |\n| `NadLambino\\Uploadable\\Events\\AfterUpload::class` | Fired when the file was successfully uploaded and file information has been stored in the `uploads` table. This event may fired up multiple times depending on the number of files that is being uploaded | `Model $uploadable`, `Upload $upload` |\n| `NadLambino\\Uploadable\\Events\\CompleteUpload::class` | Fired when all of the files are uploaded and all of the necessary clean ups has been made | `Model $uploadable`, `Collection $uploads` |\n| `NadLambino\\Uploadable\\Events\\FailedUpload::class` | Fired when an exception was thrown while trying to upload a specific file. | `Throwable $exception`, `Model $uploadable` |\n\nIf you want to do something before the file information is stored to the `uploads` table, you can define the `beforeSavingUpload` public method in your model. This method will be called after the file is uploaded in the storage and before the file information is saved in the database.\n\n```php\npublic function beforeSavingUpload(Upload $upload, Model $model) : void\n{\n    $upload-\u003eadditional_field = \"some value\";\n}\n```\n\nAlternatively, you can statically call the `beforeSavingUploadUsing` method and pass a closure.\nThe closure will receive the same parameters as the `beforeSavingUpload` method.\nJust make sure that you call this method before creating or updating the model.\nAlso, `beforeSavingUploadUsing` has the higher precedence than the `beforeSavingUpload` allowing you to override it when needed.\n\n```php\nPost::beforeSavingUploadUsing(function (Upload $upload, Post $model) use ($value) {\n    $model-\u003eadditional_field = $value;\n});\n\n$post-\u003esave();\n```\n\n\u003e [!IMPORTANT]\n\u003e \n\u003e Remember, when you're on a queue, you are actually running your upload process in a different\n\u003e application instance so you don't have access to the current application state like the request object.\n\u003e Also, make sure that the closure and its dependencies you passed to the `beforeSavingUploadUsing` method are serializable.\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Queueing\n\nYou can queue the file upload process by defining the queue name in the config.\n\n```php\n'upload_on_queue' =\u003e null,\n```\n\nAlternatively, you can also call the static method `uploadOnQueue`.\n\n```php\nPost::uploadOnQueue('default');\n\n$post-\u003esave();\n```\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Testing\n\n```bash\ncomposer test\n```\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## Credits\n\n- [Ronald Lambino](https://github.com/nadlambino)\n- [All Contributors](../../contributors)\n\n\u003chr style=\"border-bottom: 3px solid #dadada\" /\u003e\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnadlambino%2Flaravel-uploadable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnadlambino%2Flaravel-uploadable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnadlambino%2Flaravel-uploadable/lists"}