{"id":30044486,"url":"https://github.com/backstagephp/media","last_synced_at":"2025-08-07T06:18:02.114Z","repository":{"id":300771019,"uuid":"893399064","full_name":"backstagephp/media","owner":"backstagephp","description":"Media Library \u0026 Picker for Filament","archived":false,"fork":false,"pushed_at":"2025-06-23T13:48:20.000Z","size":199,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-23T14:44:02.143Z","etag":null,"topics":["filament","filament-plugin","laravel","media","media-library"],"latest_commit_sha":null,"homepage":"https://backstagephp.com/docs/media","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/backstagephp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"vormkracht10"}},"created_at":"2024-11-24T10:51:09.000Z","updated_at":"2025-06-23T13:48:25.000Z","dependencies_parsed_at":"2025-06-23T14:54:10.456Z","dependency_job_id":null,"html_url":"https://github.com/backstagephp/media","commit_stats":null,"previous_names":["backstagephp/media"],"tags_count":0,"template":false,"template_full_name":"vormkracht10/filament-plugin-template","purl":"pkg:github/backstagephp/media","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backstagephp%2Fmedia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backstagephp%2Fmedia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backstagephp%2Fmedia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backstagephp%2Fmedia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/backstagephp","download_url":"https://codeload.github.com/backstagephp/media/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backstagephp%2Fmedia/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269208593,"owners_count":24378703,"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-08-07T02:00:09.698Z","response_time":73,"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":["filament","filament-plugin","laravel","media","media-library"],"created_at":"2025-08-07T06:17:58.389Z","updated_at":"2025-08-07T06:18:02.101Z","avatar_url":"https://github.com/backstagephp.png","language":"PHP","funding_links":["https://github.com/sponsors/vormkracht10"],"categories":[],"sub_categories":[],"readme":"# Backstage Media: Media Library \u0026 Picker for Filament\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/backstagephp/media.svg?style=flat-square)](https://packagist.org/packages/backstagephp/media)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/backstagephp/media/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/backstagephp/media/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/backstagephp/media/fix-php-code-styling.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/backstagephp/media/actions?query=workflow%3A\"Fix+PHP+code+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/backstagephp/media.svg?style=flat-square)](https://packagist.org/packages/backstagephp/media)\n\n## Nice to meet you, we're [Vormkracht10](https://vormkracht10.nl)\n\nHi! We are a web development agency from Nijmegen in the Netherlands and we use Laravel for everything: advanced websites with a lot of bells and whitles and large web applications.\n\n## About the package\n\nThis package is a media picker and library for Filament. It allows you to easily add a media picker to your Filament forms and use it to select images, videos, and other media files from your media library. It also provides a media library that you can use to manage your media files.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require backstagephp/media\n```\n\nYou can publish and run the migrations with:\n\n```bash\nphp artisan vendor:publish --tag=\"media-migrations\"\n```\n\n\u003e [!NOTE]\n\u003e When you are making use of tenancy, make sure to run the migrations **after** configuring the package using the config file. This will create the media table in your database with the correct columns.\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"media-config\"\n```\n\nThis is the contents of the published config file:\n\n```php\nreturn [\n    'accepted_file_types' =\u003e [\n        'image/jpeg',\n        'image/png',\n        'image/webp',\n        'image/svg+xml',\n        'application/pdf',\n    ],\n\n    'directory' =\u003e 'media',\n\n    'disk' =\u003e env('FILAMENT_FILESYSTEM_DISK', 'public'),\n\n    'should_preserve_filenames' =\u003e false,\n\n    'should_register_navigation' =\u003e true,\n\n    'visibility' =\u003e 'public',\n\n    // Tenancy\n    'is_tenant_aware' =\u003e true,\n    'tenant_ownership_relationship_name' =\u003e 'tenant',\n    'tenant_relationship' =\u003e 'tenant',\n    // 'tenant_model' =\u003e \\App\\Models\\Tenant::class,\n\n    // Model and resource\n    'model' =\u003e \\Backstage\\Media\\Models\\Media::class,\n\n    // 'user_model' =\u003e \\App\\Models\\User::class,\n\n    'resources' =\u003e [\n        'label' =\u003e 'Media',\n        'plural_label' =\u003e 'Media',\n        'navigation_group' =\u003e null,\n        'navigation_label' =\u003e 'Media',\n        'navigation_icon' =\u003e 'heroicon-o-photo',\n        'navigation_sort' =\u003e null,\n        'navigation_count_badge' =\u003e false,\n        'resource' =\u003e \\Backstage\\Media\\Resources\\MediaResource::class,\n    ],\n];\n```\n\nAfter publishing the config file and running the migrations you should add the following code to your `PanelServiceProvider` to include the media picker in your Filament application:\n\n```php\n\nuse Filament\\Support\\Assets\\Css;\nuse Backstage\\Media\\Media;\nuse Filament\\Support\\Facades\\FilamentAsset;\n\npublic function panel(Panel $panel): Panel\n{\n    // ...\n\n    FilamentAsset::register([\n        Css::make('media', __DIR__ . '/../vendor/backstagephp/media/resources/dist/media.css'),\n    ], package: 'backstagephp/media');\n\n    // ...\n\n    return $panel\n        -\u003eplugins([\n            MediaPlugin::make()\n                -\u003econfigureTenant('site', Site::class), // Optional\n        ]);\n}\n```\n\n## Usage\n\n### Adding the media field to the Backstage CMS\n\nAdd the `Media` field to the `fields.php` config file:\n\n```php\nreturn [\n    'fields' =\u003e [\n        Backstage\\Media\\Fields\\Media::class,\n    ],\n];\n```\n\n### Tenancy\n\nIf you are using tenancy, you can set the `is_tenant_aware` config option to `true` and set the `tenant_ownership_relationship_name` and `tenant_relationship` config options to the names of the relationships on the media model and the tenant model, respectively. You can also set the `tenant_model` config option to the fully qualified class name of the tenant model.\n\n### File upload (with relationship)\n\nIf you want to be able to setup a relationship between a model and a media file, you can add the `Backstage\\Media\\Concerns\\HasMedia` trait on the model to easily attach a media file to the model. You can then use the following methods to define the relationship:\n\n```php\n$model-\u003eattachMedia($mediaUlid);\n\n// or with meta data\n$model-\u003eattachMedia($mediaUlid, [\n    'position' =\u003e 1,\n    'meta' =\u003e ['description' =\u003e 'Profile picture']\n]);\n```\n\n### Media Picker component\n\nYou can use the `Media` component in your forms to add a media picker to your Filament forms. The `Media` component is a `FileUpload` field that respects the `media` config file.\n\n```php\nuse Backstage\\Media\\Components\\Media;\n\nMedia::make('media'),\n```\n\n### Handle record creation\n\nTo handle the creation of a record with a media file, you can use the `Backstage\\Media\\Media` class to handle the file upload and attach the media file to the record.\n\n#### Creating resources\n\n```php\nuse Backstage\\Media\\Media;\n\nprotected function mutateFormDataBeforeCreate(array $data): array\n{\n    unset($data['media']);\n\n    // ...\n\n    return $data;\n}\n\nprotected function afterCreate(): void\n{\n    // ...\n\n    $media = Media::create($this-\u003edata['media']);\n\n    foreach ($media as $value) {\n        $this-\u003egetRecord()-\u003eattachMedia($value-\u003eulid);\n    }\n}\n```\n\n#### Editing resources\n\n```php\nuse Backstage\\Media\\Media;\n\nprotected function mutateFormDataBeforeFill(array $data): array\n{\n    $data['media'] = $this-\u003egetRecord()-\u003emedia-\u003emap(function ($media) {\n        return 'media/' . $media-\u003efilename;\n    })-\u003etoArray();\n\n    return $data;\n}\n\nprotected function mutateFormDataBeforeSave(array $data): array\n{\n    $media = Media::create($data['media']);\n\n    unset($data['media']);\n\n    foreach ($media as $value) {\n        $this-\u003egetRecord()-\u003eattachMedia($value-\u003eulid);\n    }\n\n    return $data;\n}\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n-   [Baspa](https://github.com/vormkracht10)\n-   [All Contributors](../../contributors)\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%2Fbackstagephp%2Fmedia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbackstagephp%2Fmedia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbackstagephp%2Fmedia/lists"}