Example #1
0
 public function upload(Request $request, Bus $bus, Receiver $receiver, Events $events, MessageBag $messageBag)
 {
     try {
         return $receiver->receive(function ($destination) use($request, $bus) {
             $name = $request->input('flowFilename');
             $description = ['name' => $name, 'path' => $destination, 'title' => $name, 'alt' => $name, 'caption' => $name, 'description' => $name, 'storage' => config('filesystems.default'), 'visibility' => config('inoplate.media.library.default_visibility', 'public'), 'is_moved' => false];
             $userId = $request->user()->id;
             $bus->dispatch(new Commands\CreateNewLibrary($userId, $description));
             $uploaded = $this->libraryRepository->findByPath($destination);
             return $this->formSuccess(route('media.admin.libraries.update.get', ['id' => $uploaded->id()->value()]), ['message' => trans('inoplate-media::messages.library.created'), 'library' => $this->generateReturnedData($uploaded->toArray())]);
         });
     } catch (Exceptions\MaximumUploadSizeExceededException $e) {
         $events->fire(new FileWasFailedToUpload($e->getUploadedFiles()));
         $messageBag->add('file', trans('inoplate-media::messages.library.file_too_large', ['size' => config('inoplate.media.library.size.max') . 'M']));
         return $this->formError(422, $messageBag->toArray());
     } catch (Exceptions\UnallowedFileExtensionException $e) {
         $events->fire(new FileWasFailedToUpload($e->getUploadedFiles()));
         $meta = $e->getLibraryMeta();
         $messageBag->add('file', trans('inoplate-media::messages.library.invalid_extension', ['extension' => $meta['extension']]));
         return $this->formError(422, $messageBag->toArray());
     }
 }
 /**
  * Handle job
  * 
  * @param  MarkNotificationAsViewed $job
  * @return void
  */
 public function handle(MarkNotificationAsViewed $job)
 {
     $userId = $job->userId;
     $this->notificationRepository->setNotificationAsViewed($userId);
     $this->events->fire([new NotificationWasMarkedAsUnviewed($userId)]);
 }
 /**
  * Handle event
  * 
  * @param  NotificationWasMarkedAsUnviewed $event
  * @return void
  */
 public function handle(NotificationWasMarkedAsUnviewed $event)
 {
     $userId = $event->userId;
     $total = $this->notificationRepository->countUnviewedByUserId($userId);
     $this->events->fire([new NotificationUnviewedRecounted($total, $userId)]);
 }
 /**
  * Handle created event
  * 
  * @param  Eloquent $model
  * @return void
  */
 public function created($model)
 {
     $this->events->fire(new NewNotificationCreated($model));
 }