Automatic Configuration of SEO Image URL with Spatie Media Library File Upload

Hello everybody Is it possible to have the behavior given by ->afterStateUpdated with this component? For now I am getting the url of the temporary image, but the component doesn't receive a string so it gives me this error "foreach() argument must be of type array|object, string given" Forms\Components\SpatieMediaLibraryFileUpload::make('image') ->collection('main') ->enableReordering() ->preserveFilenames() ->afterStateUpdated(function ($state, Forms\Set $set) { if ($state instanceof \Illuminate\Http\UploadedFile) { $temporaryFile = $state; $path = Storage::disk('public')->putFile('images', $temporaryFile); $url = Storage::disk('public')->url($path); $set('meta.image_url', $url); } elseif ($state instanceof \Filament\Forms\Components\SpatieMediaLibraryFileUpload\File) { $set('meta.image_url', $state->link()); } }) ->columnSpanFull(), // Component Forms\Components\SpatieMediaLibraryFileUpload::make('image_url') So I don't know if there is a better approach than what I am doing. Thank you very much.
0 Replies
No replies yetBe the first to reply to this messageJoin