{"id":13759584,"url":"https://github.com/classic-o/nova-media-library","last_synced_at":"2025-05-10T09:33:10.305Z","repository":{"id":34323656,"uuid":"177349190","full_name":"classic-o/nova-media-library","owner":"classic-o","description":"Media Library for admin panel \"Laravel Nova\"","archived":false,"fork":false,"pushed_at":"2023-10-03T22:59:29.000Z","size":10859,"stargazers_count":156,"open_issues_count":6,"forks_count":69,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-14T04:55:24.210Z","etag":null,"topics":["laravel","media-library","nova"],"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/classic-o.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2019-03-23T23:06:59.000Z","updated_at":"2024-12-16T01:37:53.000Z","dependencies_parsed_at":"2024-06-18T17:07:22.707Z","dependency_job_id":"f0762266-0fec-4809-b73d-84284969f6e2","html_url":"https://github.com/classic-o/nova-media-library","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/classic-o%2Fnova-media-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/classic-o%2Fnova-media-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/classic-o%2Fnova-media-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/classic-o%2Fnova-media-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/classic-o","download_url":"https://codeload.github.com/classic-o/nova-media-library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253397410,"owners_count":21902027,"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":["laravel","media-library","nova"],"created_at":"2024-08-03T13:00:55.711Z","updated_at":"2025-05-10T09:33:09.651Z","avatar_url":"https://github.com/classic-o.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Laravel Nova Media Library\n\nTool and Field for [Laravel Nova](https://nova.laravel.com) that will let you managing files and add them to the posts.\n\n##### Table of Contents\n* [Features](#features)\n* [Migration from 0.x to 1.x](#migration-from-0x-to-1x)\n* [Requirements](#requirements)\n* [Install](#install)\n* [Configuration](#configuration)\n* [Usage](#usage)\n* [Customization](#customization)\n* [Upload by url or path](#upload-by-url-or-path)\n* [Get files by ids](#get-files-by-ids)\n* [Private files](#private-files)\n* [Localization](#localization)\n* [Screenshots](#screenshots)\n\n### Features\n\n- [x] Store and manage your media files\n- [x] Use field for single file\n- [x] Use field for array of files\n- [x] Upload files by url/path\n- [x] Integrate Media Field with Trix editor\n- [x] Implement custom JS callback for field\n- [x] Automatic resize image on the backend by width\\height\n- [x] Cropping image on the frontend\n- [x] Ability to create image size variations\n- [x] Organize files in single folder, separate by date or by manageable folders\n- [x] Ability to control files visibility\n\n### Migration from 0.x to 1.x\n\nIn version 1.x, the configuration file and database migration have been changed.  \nAfter upgrading to version 1.x, you need to remove the old table from the database, then reinstall and reconfigure these files.\n\n### Requirements\n\n- Laravel 5.8+\n- Nova 2\n- [intervention/image](http://image.intervention.io) package for image resizing (optional)\n\n### Install\n\n```\ncomposer require classic-o/nova-media-library\n\nphp artisan vendor:publish --provider=\"ClassicO\\NovaMediaLibrary\\ToolServiceProvider\"\n\nphp artisan migrate\n\nphp artisan storage:link\n```\n\n### Configuration\n\n[See configuration file](https://github.com/classic-o/nova-media-library/blob/master/config/nova-media-library.php)\n\n### Usage\n\nAdd tool in app/Providers/NovaServiceProvider.php\n\n```\npublic function tools()\n{\n    return [\n        new \\ClassicO\\NovaMediaLibrary\\NovaMediaLibrary()\n    ];\n}\n```\n\nAdd Field to the resource.\n\n```\nuse ClassicO\\NovaMediaLibrary\\MediaLibrary;\n\nclass Post extends Resource\n{\n    ...\n     public function fields(Request $request)\n        {\n            return [\n                ...\n                MediaLibrary::make('Image'),\n                ...\n            ];\n        }\n    ...\n}\n```\n\n### Customization\n\nBy default, this field is used as single file. If you need to use as array of files, add option:\n\n```\n# Display\nMediaLibrary::make('Gallery')\n            -\u003earray(),\n```\n    \nBy default this files display automatically, `gallery` or `list` as in tool.  \nYou can set in first parameter needed display type:\n\n```\nMediaLibrary::make('Documents')\n            -\u003earray('list'),\n```\n\n_When you use array, set the casts as array to needed column in model and set type `nullable TEXT` in database_  \n_For single file - `nullable INT`_\n\nIf you want to hide files under the accordion, add the following option:\n```\nMediaLibrary::make('Gallery')\n            -\u003earray()\n            -\u003ehidden()\n```\n\nYou can limit the selection of files by type (Labels of types from configuration file).\n\n```\nMediaLibrary::make('File')\n            -\u003etypes(['Audio', 'Video'])\n```\n\nTo set preview size of images in fields, add the following option (Label of cropped additional image variation)  \nBy default, the preview size is set in the configuration file.\n\n```\nMediaLibrary::make('File')\n            -\u003epreview('thumb')\n```\n\nYou can also integrate the Media Field with the Trix editor.\nYou need to set a unique name in the `trix` option and add an additional attribute with the same name in the Trix field:\n\n```\nMediaLibrary::make('For Trix')\n            -\u003etrix('unique_trix_name'),\n\nTrix::make('Content')\n    -\u003ewithMeta([ 'extraAttributes' =\u003e [ 'nml-trix' =\u003e 'unique_trix_name' ] ])\n```\n\nFor set a custom callback for the Media Field, use the method `jsCallback`.\n- The first parameter set as the name of the JS function callback.\n- The second (optional) is an array of advanced options\n\n```\nMediaLibrary::make('JS Callback')\n\t        -\u003ejsCallback('callbackName', [ 'example' =\u003e 'Nova' ]),\n```\n\nYour JavaScript callback should have 2 parameters. The first will be an array of files, second - your options.\n\n```\nwindow.callbackName = function (array, options) {\n  console.log(array, options);\n}\n```\n\n_When you use JS Callback or Trix option two or more times on one resource, set second parameter of make method to any unique name_\n\n```\nMediaLibrary::make('JS Callback', 'js_cb_name_1')\n\t        -\u003ejsCallback('callbackName', [ 'example' =\u003e 'Nova' ]),\nMediaLibrary::make('Trix Field', 'trix_name_1')\n\t        -\u003etrix('unique_trix_name'),\n```\n\n### Upload by url or path\n\nAlso you can programmatically add files to the media library by url or path.\n\n```\nuse \\ClassicO\\NovaMediaLibrary\\API;\n\n$result = API::upload('https://pay.google.com/about/static/images/social/og_image.jpg');\n```\n\nIf upload done successfully, function return instance of model.  \nIf an error occurred while loading, function will throw exception.\n  \nExceptions (`code =\u003e text`):  \n`0` - `The file was not downloaded for unknown reasons`  \n`1` - `Forbidden file format`  \n`2` - `File size limit exceeded`\n\n### Get files by ids\n\nIn your model stores only id of file(s). To get files, use the API class method:\n\n```\n$files = API::getFiles($ids, $imgSize = null, $object = false);\n\n# First parameter - id or array of ids\n# Second - if you want to get images by size variation, write label of size\n# Third - by default function return array of urls. If you want to get full data of files - set true (returns object / array of objects)\n```\n\n### Private files\n\nWhen you use local storage or s3 (with private visibility), you can't get files by url.    \nTo get file, you need to create a GET Route with the name `nml-private-file` with parameter `id` and optional `img_size`. In controller add validation user access.    \nIf access is allowed, you can get file by API method:\n\n```\n... Verifying access\n\n$file = API::getFiles($id, null, true);\nreturn API::getPrivateFile($file-\u003epath, request('img_size'))\n```\n\n### Localization\n\nTo translate this tool another language, you need to add the translation file `/resources/lang/vendor/nova-media-library/{lang}.json` by adding phrases from [en.json](https://github.com/classic-o/nova-media-library/tree/master/resources/lang/en.json)\n\n### Screenshots\n\n![Media Library](https://raw.githubusercontent.com/classic-o/nova-media-library/master/docs/screenshot_1.png)\n\n![Media Library](https://raw.githubusercontent.com/classic-o/nova-media-library/master/docs/screenshot_2.png)\n\n![Details](https://raw.githubusercontent.com/classic-o/nova-media-library/master/docs/screenshot_3.png)\n\n![Crop Image](https://raw.githubusercontent.com/classic-o/nova-media-library/master/docs/screenshot_4.png)\n\n![Index Field](https://raw.githubusercontent.com/classic-o/nova-media-library/master/docs/screenshot_5.png)\n\n![Form Field](https://raw.githubusercontent.com/classic-o/nova-media-library/master/docs/screenshot_6.png)\n\n![Record](https://raw.githubusercontent.com/classic-o/nova-media-library/master/docs/record.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclassic-o%2Fnova-media-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclassic-o%2Fnova-media-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclassic-o%2Fnova-media-library/lists"}