Exemplo n.º 1
0
 /**
  * Get the message container for the validator.
  *  错误信息是数组格式
  * @return \Illuminate\Support\MessageBag
  */
 public function messagesInfo()
 {
     if (!$this->messages) {
         $this->passes();
     }
     return $this->messages->toArray();
 }
Exemplo n.º 2
0
 /**
  * Returns response for browser
  */
 public function response($redirect = null)
 {
     if ($this->request->ajax() || $this->request->wantsJson()) {
         return new JsonResponse(['formErrors' => $this->messageBag->toArray()], 422);
     }
     return \Redirect::to($redirect)->withErrors($this->messageBag->toArray());
 }
Exemplo n.º 3
0
 /**
  * Get the errors attribute
  * @param boolean toArray
  *
  * @return mixed
  */
 public function getErrors($toArray = false)
 {
     if ($toArray) {
         return $this->errors->toArray();
     } else {
         return $this->errors;
     }
 }
Exemplo n.º 4
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());
     }
 }
Exemplo n.º 5
0
 /**
  * Return the errors as an array
  *
  * @param  string $filter
  * @return array
  */
 public function getErrors($filter = null)
 {
     // Create an array to hold errors
     $messages = [];
     // If we have no errors, abort
     if (!$this->errors->count()) {
         return $messages;
     }
     foreach ($this->errors->toArray() as $key => $error) {
         $messages[$key] = $this->extractErrors($error);
     }
     // Return a specific set of messages if asked
     return array_get($messages, $filter);
 }
Exemplo n.º 6
0
 /**
  * 作成処理
  *
  * @param WorkDiaryStoreRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(WorkDiaryStoreRequest $request)
 {
     $errors = new MessageBag();
     DB::transaction(function () use($request, &$errors) {
         $fieldIds = (array) $request->input('field_ids');
         $workFields = WorkField::whereIn('id', $fieldIds)->lockForUpdate()->get();
         if (!WorkField::whereIn('id', $fieldIds)->hasActiveDiary()->get()->isEmpty()) {
             // 編集中日誌のある圃場が選択されている
             $errors->add('field_ids', message('others_update'));
             DB::rollBack();
             return;
         }
         foreach ($workFields as $workField) {
             // 日誌を作成
             $workDiary = new WorkDiary();
             $workDiary->crop_id = $request->get('crop_id');
             $workDiary->work_field_id = $workField->id;
             $workDiary->archive = false;
             $workDiary->fill($request->all());
             $workDiary->save();
         }
     });
     if ($errors->any()) {
         return $this->buildFailedValidationResponse($request, $errors->toArray());
     }
     return redirect()->route('workDiary.index')->with('complete', 'store');
 }
Exemplo n.º 7
0
 /**
  * 作成処理
  *
  * @param WorkRecordStoreRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(WorkRecordStoreRequest $request)
 {
     $cropId = $request->input('crop_id');
     $errors = new MessageBag();
     DB::transaction(function () use($request, $cropId, &$errors) {
         $workId = $request->input('work_id');
         $workDiaryIds = (array) $request->input('work_diary_ids');
         $work = Work::findOrFail($workId);
         $workDiaries = WorkDiary::whereIn('id', $workDiaryIds)->lockForUpdate()->get();
         if ($workDiaries->count() !== $workDiaries->where('crop_id', $cropId)->where('archive', false)->count()) {
             // 不正な作業日誌が選択されている
             $errors->add('work_diary_ids', message('others_update'));
             DB::rollBack();
             return;
         }
         // 作業記録登録
         $workRecord = new WorkRecord();
         $workRecord->fill($request->all());
         $workRecord->work_id = $workId;
         $workRecord->crop_id = $cropId;
         // use_complete=falseの場合は常にtrue
         $workRecord->complete = !$work->use_complete || $request->has('complete');
         $workRecord->save();
         // 防除記録
         if ($work->use_pest_control) {
             $sessionPesticides = session()->get('workRecord.pesticides');
             $pesticideIds = $sessionPesticides->keys();
             $pesticides = Pesticide::whereIn('id', $pesticideIds)->whereHas('crops', function ($query) use($cropId) {
                 $query->where('crop_id', $cropId);
             });
             if ($pesticideIds->count() !== $pesticides->count()) {
                 // 農薬の選択が不正
                 $errors->add('pesticide', message('others_update'));
                 DB::rollBack();
                 return;
             }
             foreach ($sessionPesticides as $sessionPesticide) {
                 $workPestControl = new WorkPestControl();
                 $workPestControl->work_record_id = $workRecord->id;
                 $workPestControl->pesticide_id = $sessionPesticide->get('pesticide_id');
                 $workPestControl->usage = $sessionPesticide->get('usage');
                 $workPestControl->save();
             }
         }
         // 播種/定植記録
         if ($work->use_seeding) {
             $workSeeding = new WorkSeeding();
             $workSeeding->work_record_id = $workRecord->id;
             $workSeeding->cultivar_id = $request->input('cultivar_id');
             $workSeeding->fill($request->all());
             $workSeeding->save();
         }
         // 日誌紐付け
         $workRecord->workDiaries()->attach($workDiaryIds);
     });
     if ($errors->any()) {
         return $this->buildFailedValidationResponse($request, $errors->toArray());
     }
     // 農薬情報をクリア
     session()->forget('workRecord.pesticides');
     return redirect()->route('workRecord.index', ['crop_id' => $cropId])->with('complete', 'store');
 }
Exemplo n.º 8
0
 /**
  * Get the instance as an array.
  *
  * @return array
  */
 public function toArray()
 {
     return array('id' => $this->id, 'type' => $this->type, 'settings' => $this->settings, 'heading' => $this->heading, 'messages' => $this->messages->toArray());
 }
Exemplo n.º 9
0
 protected function failure_validate(\Illuminate\Support\MessageBag $messagebag)
 {
     $errors = $messagebag->toArray();
     $messages = [];
     foreach ($errors as $lines) {
         foreach ($lines as $message) {
             $messages[] = trans(Lang::has('validation.failure_post.list') ? 'validation.failure_post.list' : 'core::common.validation.failure_post.list', compact('message'));
         }
     }
     return $this->_make_output('failure', 'validation.failure_post', FALSE, ['errors' => $errors, 'messages' => implode($messages)], TRUE);
 }
Exemplo n.º 10
0
 /**
  * Response exception message and code
  *
  * @param $e
  *
  * @return \Illuminate\Http\JsonResponse
  */
 protected function responseException($e)
 {
     $messageBag = new MessageBag();
     $messageBag->add('exception', $e->getMessage());
     return Response::json($messageBag->toArray(), $e->getCode());
 }