/** * 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; }
/** * 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(); }
/** * Medias attribute retuned by Medias Table * @return mixed */ public function getMediasAttribute() { return Media::where('table', $this->table)->where('table_id', $this->id)->get(); }
public function file() { return Media::where('table', $this->table)->where('table_id', $this->id)->first(); }