Livewire / Spatie Medialibrary PRO current value
I'm using Livewire components from Spatie Medialibrary PRO to upload user avatars.
In the past, I have used Vue components and could pass the :initial-value to the component in order to preview/show the current avatar for the user.
But I'm not being able to achieve this with the Livewire version of the components, and the documentation doesn't mention this.
I have inspected the source code and the constructor doesn't include any inital/current parameter:
public function __construct(
public string $name,
public string $rules = '',
public $multiple = false,
public $editableName = false,
public ?int $maxItems = null,
public ?string $componentView = null,
public ?string $listView = null,
public ?string $itemView = null,
?string $propertiesView = null
) {
$this->media = old($name) ?? [];
$this->propertiesView = $propertiesView ?? 'media-library::livewire.partials.attachment.properties';
}
Do I have to convert the current Media model to an array replicating the temporary array created when a file is selected? I tried doing getFirstMedia('avatar')->toArray(), but it didn't work.
Or should I just display the preview in my own img tag and just fill the input when the user is replacing that image?
Any tips or past experiences? Thanks!
Please or to participate in this conversation.