Manage your media files using spatie media library with easy to use GUI for FilamentPHP
composer require tomatophp/filament-media-manager
now you need to publish media migration
php artisan vendor:publish --provider="SpatieMediaLibraryMediaLibraryServiceProvider" --tag="medialibrary-migrations"
after install your package please run this command
php artisan filament-media-manager:install
finally register the plugin on /app/Providers/Filament/AdminPanelProvider.php
, if you like to use GUI and Folder Browser.
->plugin(TomatoPHPFilamentMediaManagerFilamentMediaManagerPlugin::make())
->schema()
you can use the media manager by add this code to your filament component
use TomatoPHPFilamentMediaManagerFormMediaManagerInput;
public function form(Form $form)
{
return $form->schema([
MediaManagerInput::make('images')
->disk('public')
->schema([
FormsComponentsTextInput::make('title')
->required()
->maxLength(255),
FormsComponentsTextInput::make('description')
->required()
->maxLength(255),
]),
]);
}
you can add custom preview to selected type on the media manager by add this code to your provider
use TomatoPHPFilamentMediaManagerFacadeFilamentMediaManager;
use TomatoPHPFilamentMediaManagerServicesContractsMediaManagerType;
public function boot() {
FilamentMediaManager::register([
MediaManagerType::make('.pdf')
->icon('bxs-file-pdf')
->preview('media-manager.pdf'),
]);
}
on your view file you can use it like this
4">
you can attach global js
or css
file to the media manager by add this code to your provider
use TomatoPHPFilamentMediaManagerFacadeFilamentMediaManager;
use TomatoPHPFilamentMediaManagerServicesContractsMediaManagerType;
public function boot() {
FilamentMediaManager::register([
MediaManagerType::make('.pdf')
->js('https://mozilla.github.io/pdf.js/build/pdf.mjs'),
->css('https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.3.136/pdf_viewer.min.css'),
->icon('bxs-file-pdf')
->preview('media-manager.pdf'),
]);
}
please note that the name
of the component will be the same name of the collection.
you can allow create and manage subfolders on your media manager on /app/Providers/Filament/AdminPanelProvider.php
->plugin(
TomatoPHPFilamentMediaManagerFilamentMediaManagerPlugin::make()
->allowSubFolders()
)
now you can allow user to access selected folder and restract user to access each other folders if the folder is not public on /app/Providers/Filament/AdminPanelProvider.php
->plugin(
TomatoPHPFilamentMediaManagerFilamentMediaManagerPlugin::make()
->allowUserAccess()
)
now on your user model you can use this trait to allow user to access selected folder
use TomatoPHPFilamentMediaManagerTraitsInteractsWithMediaFolders;
class User extends Authenticatable
{
use InteractsWithMediaFolders;
}
NOTE don't forget to migrate after update the plugin
now you can access your media and folders using API you have 2 endpoints
/api/folders
to get all folders/api/folders/{id}
to get folder by id with sub folders and media filesto allow this feature you need to publish the config file by use this command
php artisan vendor:publish --tag="filament-media-manager-config"
then you can set api.active
to true
on the config file
'api' => [
"active" => true,
],
you can publish config file by use this command
php artisan vendor:publish --tag="filament-media-manager-config"
you can publish views file by use this command
php artisan vendor:publish --tag="filament-media-manager-views"
you can publish languages file by use this command
php artisan vendor:publish --tag="filament-media-manager-lang"
you can publish migrations file by use this command
php artisan vendor:publish --tag="filament-media-manager-migrations"
Checkout our Awesome TomatoPHP