Пример #1
0
 /**
  * Generates an avatar based on the current users initials.
  *
  * @param $image UploadedFile
  *
  * @throws \Exception
  *
  * @return bool
  */
 protected function generate(UploadedFile $image = null)
 {
     $user = Auth::user();
     if ($user->has_avatar) {
         // If the user has an avatar already, we'll make sure
         // we delete it before generating another.
         $user->avatar()->delete();
     }
     if ($image) {
         // Generate the uploaded images file name.
         $fileName = sprintf('%s.%s', $user->id, $image->getClientOriginalExtension());
         // If we've been given an uploaded image we'll retrieve the contents.
         $image = $this->resize($image)->stream();
     } else {
         // Generate the initials image file name.
         $fileName = $user->id . '.jpg';
         // Otherwise we'll generate and retrieve the initials image contents.
         $image = $this->initialcon->getImageData($user->present()->initials(), $user->email, $this->size);
     }
     // Generate the storage path.
     $path = $this->path($fileName);
     // Move the file into storage.
     Storage::put($path, $image);
     // Add the file to the user.
     return $user->addAvatar($path);
 }