FabioFratini 1 anno fa
parent
commit
a3f4b8d27a
1 ha cambiato i file con 11 aggiunte e 0 eliminazioni
  1. 11 0
      app/Http/Livewire/Traits/HasAllegato.php

+ 11 - 0
app/Http/Livewire/Traits/HasAllegato.php

@@ -19,6 +19,7 @@ trait HasAllegato
     public $allegatiDocumenti;
     public $allegati = [];
 
+    protected $imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp'];
 
     public function getAllegatoType($type)
     {
@@ -43,6 +44,16 @@ trait HasAllegato
 
     public function saveAllegato()
     {
+        if ($this->allegatoGallery == 1) {
+            foreach ($this->allegatiFiles as $file) {
+                $extension = pathinfo($file, PATHINFO_EXTENSION);
+                if (!in_array(strtolower($extension), $this->imageExtensions)) {
+                    session()->flash('error', 'I File devono essere immagini per Tipologia: foto sinistro');
+                    return;
+                }
+            }
+        }
+
         $files = implode("|", $this->allegatiFiles);
 
         if ($this->allegatoId > 0) {