{"id":20388591,"url":"https://github.com/efureev/laravel-files","last_synced_at":"2026-04-20T07:02:07.157Z","repository":{"id":62504267,"uuid":"163087453","full_name":"efureev/laravel-files","owner":"efureev","description":null,"archived":false,"fork":false,"pushed_at":"2019-01-23T13:57:13.000Z","size":1898,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-15T09:02:46.555Z","etag":null,"topics":["file","image","laravel","laravel-package"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/efureev.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-25T14:01:37.000Z","updated_at":"2022-03-16T19:21:56.000Z","dependencies_parsed_at":"2022-11-02T12:15:55.756Z","dependency_job_id":null,"html_url":"https://github.com/efureev/laravel-files","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Flaravel-files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Flaravel-files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Flaravel-files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Flaravel-files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/efureev","download_url":"https://codeload.github.com/efureev/laravel-files/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241940541,"owners_count":20045878,"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":["file","image","laravel","laravel-package"],"created_at":"2024-11-15T03:11:45.758Z","updated_at":"2026-04-20T07:02:07.121Z","avatar_url":"https://github.com/efureev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://poser.pugx.org/feugene/laravel-files/v/stable)](https://packagist.org/packages/feugene/laravel-files)\n[![Total Downloads](https://poser.pugx.org/feugene/laravel-files/downloads)](https://packagist.org/packages/feugene/laravel-files)\n[![Latest Unstable Version](https://poser.pugx.org/feugene/laravel-files/v/unstable)](https://packagist.org/packages/feugene/laravel-files)\n\n[![Build Status](https://travis-ci.org/efureev/laravel-files.svg?branch=master)](https://travis-ci.org/efureev/laravel-files)\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/6f7ae271de2ad9d33ccd/maintainability)](https://codeclimate.com/github/efureev/laravel-files/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/6f7ae271de2ad9d33ccd/test_coverage)](https://codeclimate.com/github/efureev/laravel-files/test_coverage)\n\n## Information\nAdd-on file model for Laravel models. Implements work with native files.\n\n\n## Install\n- `composer require feugene/laravel-files`\n\n## Examples\n- Add ServiceProvider into your app: `config/app.php` (section: `providers`)\n    ```php\n        // ...\n        Feugene\\Files\\ServiceProvider::class,\n    ```\n    or if Laravel \u003e= 5.7 - use service discover.\n\n- Run `php artisan migrate` for add table for file \n\n### File upload\n\nOnly simple upload:\n```php\npublic function store()\n{\n    $list = app(UploadService::class)\n        -\u003eupload();\n\n    return [\n        'success' =\u003e $list-\u003eisNotEmpty(),\n        'files'   =\u003e $list,\n    ];\n}\n```\n\nUpload with wrapped file to model via after actions:\n\n```php\npublic function store()\n{\n    $list = app(UploadService::class)\n        -\u003esetAfterAction(AfterModelAction::class)\n        -\u003eupload();\n\n    return [\n        'success' =\u003e $list-\u003eisNotEmpty(),\n        'files'   =\u003e $list,\n    ];\n}\n```\n\n\nUpload with wrapped file to custom model and custom path:\n\n```php\npublic function store(int $sectionId)\n{\n    /** @var Section $section */\n    $section = Section::findOrFail($sectionId);\n\n    $this-\u003eauthorize('uploadFile', $section);\n\n    $upload = new Upload($section);\n    $path = $upload-\u003egetUploadPath();\n\n    $list = app(UploadService::class)\n        -\u003esetPath($path)\n        -\u003esetAction(BeforeBaseAction::class, 'before')\n        -\u003esetAfterAction(AfterModelAction::class)\n        -\u003esetAfterAction(function ($file) use ($section) {\n            /** @var \\Feugene\\Files\\Models\\File $file */\n            \n            return File::create([\n                'section_id' =\u003e $section-\u003eid,\n                'author_id'  =\u003e \\Auth::id(),\n                'name'       =\u003e $file-\u003egetBaseFile()-\u003egetFilename(),\n                'file_id'    =\u003e $file-\u003egetKey()\n            ]);\n        })\n        -\u003eupload();\n\n    return [\n        'success' =\u003e $list-\u003eisNotEmpty(),\n        'files'   =\u003e $list,\n    ];\n}\n```\n\n\n### Relations and image operations \n\n```php\n\n// find image type from DB\n/** @var ImageFile $file */\n$file = ImageFile::find($id);\n\n// create child relation with clone image     \n$child = $file-\u003ecreateChild();\n\n// Image scale to 50% from original\n// without relation\n$child = $file-\u003escale(new ScaleModificator(50));\n// create child relation \n$child = $file-\u003ecreateChild(new ScaleModificator(50));\n\n// Image resize to 50px by width\n// without relation\n$child = $file-\u003eresize(new ResizeModificator(50));\n// create child relation \n$child = $file-\u003ecreateChild(new ResizeModificator(50));\n\n\n// Image resize to 50px by height\n// without relation\n$child = $file-\u003eresize(new ResizeModificator(null, 50));\n// create child relation \n$child = $file-\u003ecreateChild(new ResizeModificator(null, 50));\n\n\n// Image resize to 50px by height and 100px by width and bestFit options\n// without relation\n$child = $file-\u003eresize(new ResizeModificator(100, 50));\n// create child relation \n$child = $file-\u003ecreateChild(new ResizeModificator(100, 50));\n\n\n// Image resize to 50px by height and 100px by width and important size (100x50)\n// without relation\n$child = $file-\u003eresize(new ResizeModificator(100, 50, false));\n$child = $file-\u003eresize(new ResizeModificator(100, 50, false), true);  // if original image is smaller than target image\n// create child relation \n$child = $file-\u003ecreateChild(new ResizeModificator(100, 50, false));\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefureev%2Flaravel-files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fefureev%2Flaravel-files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefureev%2Flaravel-files/lists"}