/**
  * Delete multiple medias based on table name and id
  *
  * @param $table
  * @param $id
  * @return mixed
  */
 public function deleteByTable($table, $id)
 {
     $medias = Media::where('table', $table)->where('table_id', $id)->get();
     if ($medias->count() == 0) {
         return true;
     }
     $deleted = true;
     foreach ($medias as $media) {
         $this->uploadManager->deleteFile($media->path);
         $deleted = $media->delete();
     }
     return $deleted;
 }
Example #2
0
 /**
  * Return the description of spec in multiple langs
  * @return mixed
  */
 public function getImageAttribute()
 {
     return Media::where('table', $this->table)->where('table_id', $this->id)->first();
 }
Example #3
0
 /**
  * Medias attribute retuned by Medias Table
  * @return mixed
  */
 public function getMediasAttribute()
 {
     return Media::where('table', $this->table)->where('table_id', $this->id)->get();
 }
Example #4
0
 public function file()
 {
     return Media::where('table', $this->table)->where('table_id', $this->id)->first();
 }