{"id":36995452,"url":"https://github.com/esign/laravel-model-files","last_synced_at":"2026-01-13T23:47:46.797Z","repository":{"id":65741288,"uuid":"506747827","full_name":"esign/laravel-model-files","owner":"esign","description":null,"archived":false,"fork":false,"pushed_at":"2025-11-20T21:41:03.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-11-20T23:30:26.523Z","etag":null,"topics":[],"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/esign.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-06-23T18:21:21.000Z","updated_at":"2025-11-20T21:41:05.000Z","dependencies_parsed_at":"2023-11-23T20:22:12.949Z","dependency_job_id":"e7455030-baf1-471a-8d85-0cf33d3955d3","html_url":"https://github.com/esign/laravel-model-files","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"4c3cc4221fd0e9fa98b599d4d15c52d7936bec8d"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/esign/laravel-model-files","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-model-files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-model-files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-model-files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-model-files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esign","download_url":"https://codeload.github.com/esign/laravel-model-files/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-model-files/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":[],"created_at":"2026-01-13T23:47:46.729Z","updated_at":"2026-01-13T23:47:46.787Z","avatar_url":"https://github.com/esign.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Associate files with your Laravel Models\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/esign/laravel-model-files.svg?style=flat-square)](https://packagist.org/packages/esign/laravel-model-files)\n[![Total Downloads](https://img.shields.io/packagist/dt/esign/laravel-model-files.svg?style=flat-square)](https://packagist.org/packages/esign/laravel-model-files)\n![GitHub Actions](https://github.com/esign/laravel-model-files/actions/workflows/main.yml/badge.svg)\n\nThis package allows you to store files for models in an opinionated way.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require esign/laravel-model-files\n```\n\n## Usage\n### Preparing your model\nTo associate files with your model you need to use the `Esign\\ModelFiles\\Concerns\\HasFiles` trait on the model.\n```php\nuse Esign\\ModelFiles\\Concerns\\HasFiles;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model\n{\n    use HasFiles;\n}\n```\n\nThe database structure should look like the following:\n```php\nSchema::create('posts', function (Blueprint $table) {\n    $table-\u003eid();\n    $table-\u003eboolean('file')-\u003edefault(0);\n    $table-\u003estring('file_filename')-\u003enullable();\n    $table-\u003estring('file_mime')-\u003enullable();\n});\n```\n\n### Configuring the disk\nBy default, the files will be associated with the default disk configured in your `config/filesystems.php` file.\nYou may override this by defining the `getFileDisk` method on your model.\n```php\nuse Esign\\ModelFiles\\Concerns\\HasFiles;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model\n{\n    use HasFiles;\n\n    public function getFileDisk(): string\n    {\n        return 'public';\n    }\n}\n```\n\n### Storing files\nTo store files you may use the `storeFile` method.\nThis method accepts instances of both the `Illuminate\\Http\\File` and `Illuminate\\Http\\UploadedFile` classes.\n```php\n$post-\u003estoreFile('file', $request-\u003efile('attachment'));\n```\n\n### Retrieving file info\n```php\n$post-\u003ehasFile('file'); // returns true/false\n$post-\u003egetFolderPath('file'); // returns posts/file\n$post-\u003egetFilePath('file'); // returns posts/file/1.pdf\n$post-\u003egetFilePathOnDisk('file'); // returns /path/to/storage/app/public/posts/file/1.pdf\n$post-\u003egetFileMime('file'); // returns application/pdf\n$post-\u003egetFileExtension('file'); // returns pdf\n$post-\u003egetFileUrl('file'); // returns https://www.example.com/storage/posts/file/1.pdf\n$post-\u003egetVersionedFileUrl('file'); // returns https://www.example.com/storage/posts/file/1.pdf?t=1675776047\n```\n\n### Deleting files\n```php\n$post-\u003edeleteFile('file');\n```\n\n### Using with underscore translatable\nThis package ships with support for the [underscore translatable](github.com/esign/laravel-underscore-translatable) package.\n\nMake sure to include the file, filename and mime columns within the `translatable` array:\n```php\nuse Esign\\ModelFiles\\Concerns\\HasFiles;\nuse Esign\\UnderscoreTranslatable\\UnderscoreTranslatable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass UnderscoreTranslatablePost extends Model\n{\n    use HasFiles;\n    use UnderscoreTranslatable;\n\n    public $translatable = [\n        'document',\n        'document_filename',\n        'document_mime',\n    ];\n}\n```\n\nNext up, your migrations should look like the following:\n```php\nSchema::create('posts', function (Blueprint $table) {\n    $table-\u003eid();\n    $table-\u003eboolean('document_en')-\u003edefault(0);\n    $table-\u003eboolean('document_nl')-\u003edefault(0);\n    $table-\u003estring('document_filename_en')-\u003enullable();\n    $table-\u003estring('document_filename_nl')-\u003enullable();\n    $table-\u003estring('document_mime_en')-\u003enullable();\n    $table-\u003estring('document_mime_nl')-\u003enullable();\n});\n```\n\nYou may now use the internal methods using the default or the specific locale:\n```php\n$post-\u003ehasFile('document'); // returns true/false\n$post-\u003egetFolderPath('document'); // returns posts/document_en\n$post-\u003egetFilePath('document'); // returns posts/document_en/1.pdf\n$post-\u003egetFileMime('document'); // returns application/pdf\n$post-\u003egetFileExtension('document'); // returns pdf\n$post-\u003egetFileUrl('document'); // returns https://www.example.com/storage/posts/document_en/1.pdf\n$post-\u003egetVersionedFileUrl('document'); // returns https://www.example.com/storage/posts/document_en/1.pdf?t=1675776047\n```\n\n```php\n$post-\u003ehasFile('document_en'); // returns true/false\n$post-\u003egetFolderPath('document_en'); // returns posts/document_en\n$post-\u003egetFilePath('document_en'); // returns posts/document_en/1.pdf\n$post-\u003egetFileMime('document_en'); // returns application/pdf\n$post-\u003egetFileExtension('document_en'); // returns pdf\n$post-\u003egetFileUrl('document_en'); // returns https://www.example.com/storage/posts/document_en/1.pdf\n$post-\u003egetVersionedFileUrl('document_en'); // returns https://www.example.com/storage/posts/document_en/1.pdf?t=1675776047\n```\n\n### Testing\n\n```bash\ncomposer test\n```\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%2Fesign%2Flaravel-model-files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesign%2Flaravel-model-files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesign%2Flaravel-model-files/lists"}