{"id":19029971,"url":"https://github.com/padosoft/laravel-uploadable","last_synced_at":"2025-04-16T07:40:37.896Z","repository":{"id":37587534,"uuid":"65666809","full_name":"padosoft/laravel-uploadable","owner":"padosoft","description":"Laravel package for automatic upload handling with trait.","archived":false,"fork":false,"pushed_at":"2024-06-21T16:15:18.000Z","size":304,"stargazers_count":28,"open_issues_count":1,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T05:12:07.511Z","etag":null,"topics":["eloquent-models","laravel","laravel-package","trait","upload"],"latest_commit_sha":null,"homepage":null,"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/padosoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"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}},"created_at":"2016-08-14T13:10:22.000Z","updated_at":"2024-06-21T16:15:21.000Z","dependencies_parsed_at":"2023-02-17T09:46:04.391Z","dependency_job_id":"c67bd62e-a196-4680-a25b-3195c626f157","html_url":"https://github.com/padosoft/laravel-uploadable","commit_stats":{"total_commits":34,"total_committers":2,"mean_commits":17.0,"dds":"0.11764705882352944","last_synced_commit":"26b586b3149d2f037a8240b8e015557cda81983d"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padosoft%2Flaravel-uploadable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padosoft%2Flaravel-uploadable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padosoft%2Flaravel-uploadable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padosoft%2Flaravel-uploadable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/padosoft","download_url":"https://codeload.github.com/padosoft/laravel-uploadable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249213893,"owners_count":21231096,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["eloquent-models","laravel","laravel-package","trait","upload"],"created_at":"2024-11-08T21:15:59.462Z","updated_at":"2025-04-16T07:40:37.878Z","avatar_url":"https://github.com/padosoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Auto upload handling with Eloquent models trait\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/padosoft/laravel-uploadable.svg?style=flat-square)](https://packagist.org/packages/padosoft/laravel-uploadable)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/padosoft/laravel-uploadable/master.svg?style=flat-square)](https://travis-ci.org/padosoft/laravel-uploadable)\n[![Quality Score](https://img.shields.io/scrutinizer/g/padosoft/laravel-uploadable.svg?style=flat-square)](https://scrutinizer-ci.com/g/padosoft/laravel-uploadable)\n[![Total Downloads](https://img.shields.io/packagist/dt/padosoft/laravel-uploadable.svg?style=flat-square)](https://packagist.org/packages/padosoft/laravel-uploadable)\n\nThis package provides a trait that will automatic handlind upload when saving/updating/deleting any Eloquent model with upload form request.\n\n##Requires\n  \n- php: \u003e=7.1\n- illuminate/database: ^5.7|^6.0|^7.0|^8.0|^9.0\n- illuminate/support: ^5.7|^6.0|^7.0|^8.0|^9.0\n- illuminate/http: ^5.7|^6.0|^7.0|^8.0|^9.0\n- padosoft/io: \"^1.9\",\n- padosoft/laravel-request: \"^1.0|^2.0\",\n- padosoft/support: \"^1.6|^2.1|^3.0.4\"\n- \n## Installation\n\nYou can install the package via composer:\n``` bash\n$ composer require padosoft/laravel-uploadable\n```\n\n## Usage\n\nYour Eloquent models should use the `Padosoft\\Uploadable\\Uploadable` trait and the `Padosoft\\Uploadable\\UploadOptions` class.\n\nYou can define `getUploadOptions()`  method  in your model. \n\nHere's an example of how to implement the trait with implementation of getUploadOptions():\n\n```php\n\u003c?php\n\nnamespace App;\n\nuse Padosoft\\Uploadable\\Uploadable;\nuse Padosoft\\Uploadable\\UploadOptions;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass YourEloquentModel extends Model\n{\n    use Uploadable;\n    \n /**\n     * Retrive a specifice UploadOptions for this model, or return default UploadOptions\n     * @return UploadOptions\n     */\n    public function getUploadOptions() : UploadOptions\n    {\n        if($this-\u003euploadOptions){\n            return $this-\u003euploadOptions;\n        }\n\n        $this-\u003euploadOptions = UploadOptions::create()-\u003egetUploadOptionsDefault()\n            -\u003esetUploadBasePath(public_path('upload/' . $this-\u003egetTable()))\n            -\u003esetUploadsAttributes(['image', 'image_mobile']);\n\n        return $this-\u003euploadOptions;\n    }\n}\n```\n\nYou can specified uploads attributes with:\n\n```php\npublic function getUploadOptions() : UploadOptions\n{\n    return UploadOptions::create()\n        -\u003esetUploadsAttributes(['image', 'image_mobile']);\n}\n```\nYou can set the base upload path for your model:\n\n```php\npublic function getUploadOptions() : UploadOptions\n{\n    return UploadOptions::create()\n        -\u003esetUploadBasePath(public_path('upload/news'));\n}\n```\nYou can set different path for each (or for some) upload attributes in your model:\n```php\npublic function getUploadOptions() : UploadOptions\n{\n    return UploadOptions::create()\n        -\u003esetUploadPaths(['image_mobile' =\u003e '/mobile' ]);\n}\n```\n\nIt support validation to accept files by specified list of Mime Type:\n```php\npublic function getUploadOptions() : UploadOptions\n{\n    return UploadOptions::create()\n        -\u003esetMimeType([\n          'image/gif',\n          'image/jpeg',\n          'image/png',\n            ]);\n}\n```\n\nBy default every uploaded file will rename with `'original_name_'.$model-\u003eid.'.original_ext'` \nbut you can redefine a custom function for renaming file:\n\n```php\n/**\n * Generate a new file name for uploaded file.\n * Return empty string if $uploadedFile is null.\n * @param \\Illuminate\\Http\\UploadedFile $uploadedFile\n * @param String $uploadField\n * @return string\n */\npublic function generateNewUploadFileName(\\Illuminate\\Http\\UploadedFile $uploadedFile, string $uploadField) : string \n{\n    if($uploadField=='image'){\n        return 'pippo.jpg';\n    }else{\n        return 'pippo_mobile.jpg';\n    }\n}\n```\n\nThis class use Laravel 'local' Storage Disk for default.\nYou can set different disk in your model:\n```php\npublic function getUploadOptions() : UploadOptions\n{\n    return UploadOptions::create()\n        -\u003esetStorageDisk('ftp');\n}\n```\n\n\nFor all options see UploadOptions class.\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email instead of using the issue tracker.\n\n## Credits\n- [Lorenzo Padovani](https://github.com/lopadova)\n- [All Contributors](../../contributors)\n\n## About Padosoft\nPadosoft (https://www.padosoft.com) is a software house based in Florence, Italy. Specialized in E-commerce and web sites.\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%2Fpadosoft%2Flaravel-uploadable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpadosoft%2Flaravel-uploadable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadosoft%2Flaravel-uploadable/lists"}