components([ TextInput::make('title') ->required() ->live(onBlur: true) ->afterStateUpdated(function ($state, $set): void { $set('slug', Str::slug((string) $state)); }), TextInput::make('slug') ->required() ->dehydrated() ->readOnly(), Textarea::make('description') ->columnSpanFull(), SpatieMediaLibraryFileUpload::make('featured_image') ->collection('featured-image') ->image() ->imageEditor() ->columnSpanFull(), Toggle::make('is_published') ->required(), Toggle::make('is_featured') ->required(), DatePicker::make('published_at'), RichEditor::make('content') ->columnSpanFull() ->hintAction( Action::make('picker') ->label('Gallery Picker') ->icon('heroicon-m-photo') ->schema([ Select::make('image_url') ->label('Select an existing image') ->allowHtml() ->options(function () { // We must 'get' the collection first so we can call getUrl() // because 'url' is not a column in the Spatie database table. return Media::latest() ->get() ->mapWithKeys(function (Media $item) { $url = $item->getUrl(); $fileName = e($item->file_name); $name = e($item->name ?? ''); $html = "
". "\"{$fileName}\"/". "{$name} — {$fileName}
"; return [$url => $html]; })->toArray(); }) ->searchable() ->required(), ]) ->action(function (array $data, RichEditor $component) { // We dispatch the URL to the browser to be inserted into TipTap $component->getLivewire()->dispatch('insert-editor-content', [ 'statePath' => $component->getStatePath(), 'html' => "", ]); }) ), ]); } }