{"id":33994223,"url":"https://github.com/devfelipereis/uploadtrait","last_synced_at":"2025-12-13T07:48:13.210Z","repository":{"id":56966559,"uuid":"123645284","full_name":"devfelipereis/uploadtrait","owner":"devfelipereis","description":"Simple upload trait for Laravel","archived":false,"fork":false,"pushed_at":"2019-01-16T13:31:10.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T14:27:16.287Z","etag":null,"topics":["laravel","s3","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/devfelipereis.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-03T00:32:48.000Z","updated_at":"2019-04-23T12:33:54.000Z","dependencies_parsed_at":"2022-08-21T06:10:21.476Z","dependency_job_id":null,"html_url":"https://github.com/devfelipereis/uploadtrait","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devfelipereis/uploadtrait","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfelipereis%2Fuploadtrait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfelipereis%2Fuploadtrait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfelipereis%2Fuploadtrait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfelipereis%2Fuploadtrait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devfelipereis","download_url":"https://codeload.github.com/devfelipereis/uploadtrait/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfelipereis%2Fuploadtrait/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27702156,"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","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["laravel","s3","trait","upload"],"created_at":"2025-12-13T07:48:10.191Z","updated_at":"2025-12-13T07:48:13.202Z","avatar_url":"https://github.com/devfelipereis.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple upload trait for Laravel\nA simple upload trait for laravel.\nIt will upload to the local storage if in development and to a s3 bucket if in production/staging.\n\nFor production, you need to follow the laravel documentation to set s3 as your default cloud disk.\n\nJust tested with Laravel 5.4+. But it should work with Laravel 5.x.\n\nNote: This is something made for my setup and works good. I like storage for dev and s3 for production. Feel free to change whatever you like to meet your needs ;)\n\n```\nWhen not using s3, the generated url will be something like this: site.com/storage?path=something/something.jpg\nDo not use this in production, it's only for dev.\nIt is vulnerable with Full Path Disclosure (https://www.owasp.org/index.php/Full_Path_Disclosure)\n```\n\n### How to install\n\n```\ncomposer require devfelipereis/uploadtrait:dev-master\n```\nIf you are running Laravel 5.4 or below, you will need to add the service provider to the providers array in your app.php config as follows:\n\n```\nDevFelipeReis\\UploadTrait\\UploadTraitServiceProvider::class\n```\n\nNow see the example below to understand how to use it.\n\n\n# Example\n\nIn your model, set the base path for your uploads:\n\n```php\n...\nuse DevFelipeReis\\UploadTrait\\UploadTrait;\n\nclass Company extends Model\n{\n    use UploadTrait;\n\n    ...\n\n    public function getBaseUploadFolderPath() {\n        return 'companies/' . $this-\u003eid . '/';\n    }\n}\n```\n\nNow in your controller...\n\n```php\npublic function store(CreateCompanyRequest $request)\n{\n    ...\n    $inputs = $request-\u003eexcept('logo');\n    $company = $this-\u003ecompanyRepository-\u003ecreate($inputs);\n\n    // Company logo\n    $company_logo = $request-\u003efile('logo');\n    if ($company_logo) {\n        $company-\u003elogo = $company-\u003euploadFile($company_logo);\n        // $company-\u003elogo will be something like: companies/1/8e5dc57cb5d80532f52e13597c5f0b68.jpg\n    }\n\n    $company-\u003esave();\n\n    ...\n}\n```\n\n### How to access the image?\n\nFinally, inside the view:\n\n```html\n...\n\u003cimg id=\"logo-img\" class=\"thumbnail preview-img\" src=\"{{ $company-\u003egetUploadUrlFor('logo') }}\"/\u003e\n...\n```\n\n### How to delete the image?\n\nMaybe you want to delete that image, try this:\n\n```php\n$company-\u003edeleteUploadFor('photo');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevfelipereis%2Fuploadtrait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevfelipereis%2Fuploadtrait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevfelipereis%2Fuploadtrait/lists"}