private function createFile($path, $file, $table, $table_id) { $path .= "files/{$table}/"; $fileType = last(explode('.', $file->getClientOriginalName())); $name = str_replace(" ", "_", $file->getClientOriginalName()); $path .= $name; //insere o ficheiro na pasta $this->uploadManager->saveFile($path, \File::get($file)); //cria a Media $media = new Media(); $media->path = $path; $media->type = $file->getClientMimeType(); $media->name = $name; $media->table = $table; $media->table_id = $table_id; return $media->save() ? $media->id : false; }
/** * 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(); }