Integrate Media Library with Rich Editor file attachments
5.xTo use Spatie Media Library for file attachments in a Filament RichEditor, you must implement HasRichContent on your model and register a rich content attribute. Use SpatieMediaLibraryFileAttachmentProvider::make() within the fileAttachmentProvider() method during registration.
Key Provider Options:
collection('name'): Specify a custom collection name (defaults to the attribute name).preserveFilenames(): Preserves the original filenames of uploaded files.mediaName(fn...): Customizes the media name using a closure.customProperties(array): Adds custom properties to the uploaded media.
use Filament\Forms\Components\RichEditor\FileAttachmentProviders\SpatieMediaLibraryFileAttachmentProvider;
use Filament\Forms\Components\RichEditor\Models\Concerns\InteractsWithRichContent;
use Filament\Forms\Components\RichEditor\Models\Contracts\HasRichContent;
use Illuminate\Database\Eloquent\Model;
class Post extends Model implements HasRichContent
{
use InteractsWithRichContent;
public function setUpRichContent(): void
{
$this->registerRichContent('content')
->fileAttachmentProvider(SpatieMediaLibraryFileAttachmentProvider::make());
}
}