예제 #1
0
파일: User.php 프로젝트: konato-events/web
 public function setPictureAttribute($file)
 {
     if (is_string($file)) {
         $path = $file;
         //TODO: should we copy the picture to our storage instead?
     } elseif ($file instanceof UploadedFile) {
         //no $file->guessExtension() as this would create dups if the user uploads a pic with a different extension
         $rel_path = 'users/picture-' . $this->id;
         $stored = \Storage::put($rel_path, file_get_contents($file->getRealPath()));
         if (!$stored) {
             $this->errors()->add('picture', _('Sorry, we were unable to save your picture. Can you try again later?'));
         }
         $path = \Config::get('filesystems.root_url') . $rel_path;
     }
     if (isset($path)) {
         //FIXME: resize the picture to create a smaller avatar (what size?)
         $this->attributes['picture'] = $this->attributes['avatar'] = $path;
     }
 }