1. Go to this page and download the library: Download waad/filament-media library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
waad / filament-media example snippets
use Illuminate\Database\Eloquent\Model;
use Waad\Media\HasMedia;
class Post extends Model
{
use HasMedia;
public function registerCollections(array $attributes = []): array
{
return [
'avatar' => [
'disk' => 's3',
'bucket' => 'avatars',
'label' => 'User Avatar',
'single' => true, // Only keeps one file
],
'gallery' => [
'disk' => 'public',
'bucket' => 'photos',
'label' => 'Photo Gallery',
'single' => false, // Allows multiple files
],
];
}
}
use Waad\FilamentMedia\Forms\Components\MediaUpload;
public static function form(Form $form): Form
{
return $form
->schema([
// Single file when registerCollections has 'single' => true for this key
MediaUpload::make('avatar'),
// Multiple files when 'single' => false; reorderable uses waad/media `index`
MediaUpload::make('gallery')
->reorderable()
->image()
->maxSize(2048),
// Single vs multiple follows `registerCollections`; other FileUpload APIs apply as usual
]);
}