You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys. I upload some photos to the system and try to set custom properties in a loop. But the check does not work and properties are assigned to all elements.
public function upload(MediaEntity $entity, PhotosDto $dto)
{
foreach ($dto->getPhotos() as $photo) {
$name = Str::slug($entity->getName(), '_').'_'.time();
$media = $entity->addMedia($photo)->setFileName($name.'.'.$photo->getClientOriginalExtension())
->usingName($name);
if ($this->emptyMediaCollection($entity)) {
$media->withCustomProperties(['main' => true]);
}
$media->toMediaLibrary($entity->getMediaName());
}
}
protected function emptyMediaCollection(MediaEntity $mediaEntity): bool
{
return !$mediaEntity->hasMedia($mediaEntity->getMediaName());
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys. I upload some photos to the system and try to set custom properties in a loop. But the check does not work and properties are assigned to all elements.
Result

Thank you in advance
Beta Was this translation helpful? Give feedback.
All reactions