Esempio n. 1
0
 public function store(AttachmentRequest $request, Attachment $attachment)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $filename = uniqid();
     $data = $request->all();
     if ($request->hasFile('file')) {
         $extension = $request->file('file')->getClientOriginalExtension();
         $file = $request->file('file')->move('uploads/attachment_files/', $filename . "." . $extension);
         $data['file'] = $filename . "." . $extension;
     }
     $data['user_id'] = Auth::user()->id;
     $attachment->fill($data);
     $attachment->save();
     $activity = 'Attached a file on a ' . $request->input('belongs_to');
     Activity::log($activity);
     return redirect()->back()->withSuccess(config('constants.SAVED'));
 }
Esempio n. 2
0
 /**
  * Uploads and attaches files for the current relation.
  *
  * @param Filesystem $filesystem
  *
  * @return bool|array
  */
 public function handle(Filesystem $filesystem)
 {
     $files = $this->request->file('files');
     if (is_array($files)) {
         $uploaded = [];
         foreach ($files as $file) {
             // Double check that we have an uploaded file instance.
             if ($file instanceof UploadedFile) {
                 // Generates the unique file name.
                 $name = implode('.', [uuid(), $file->getClientOriginalExtension()]);
                 // Generates the complete storage path.
                 $path = implode(DIRECTORY_SEPARATOR, [$this->path, $name]);
                 // Try and move the uploaded file into storage.
                 if ($filesystem->put($path, file_get_contents($file->getRealPath()))) {
                     // Successfully moved uploaded file, create the record.
                     $attributes = ['user_id' => auth()->id(), 'name' => $file->getClientOriginalName(), 'file_name' => $name, 'file_path' => $path];
                     $uploaded[] = $this->relation->create($attributes);
                 }
             }
         }
         return $uploaded;
     }
     return false;
 }