コード例 #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $user = User::findOrFail($id);
     $input = Input::only('email', 'first_name', 'last_name', 'role_id', 'confirmed', 'county_id', 'phone', 'school', 'password');
     $extra = Input::only('address', 'about');
     try {
         $in = Input::all();
         $in['id'] = $user->id;
         $this->editUserForm->validate($in);
     } catch (FormValidationException $e) {
         $this->errors = $e->getErrors();
     }
     foreach ($input as $key => $value) {
         if (!$this->errors->has($key)) {
             if ($key === 'password' && !empty($value)) {
                 $user->password = $value;
                 continue;
             }
             $user->{$key} = $value;
         }
     }
     foreach ($extra as $key => $value) {
         if (!$this->errors->has($key)) {
             $user->setMeta($key, e($value));
         }
     }
     $user->save();
     if ($this->errors->any()) {
         return back()->withErrors($this->errors);
     }
     flash('Modificările au fost salvate cu succes.');
     return back();
 }
コード例 #2
0
ファイル: Result.php プロジェクト: hsyngkby/result
 /**
  * Show specific alert type
  * @param  string $type
  * @return string
  */
 public function render()
 {
     if ($this->bag->any()) {
         $output = array();
         foreach ($this->bag->getMessages() as $type => $messages) {
             foreach ($messages as $message) {
                 // Prepare output
                 $output[] = array('type' => $type, 'data' => $message);
             }
         }
         //$json = new JsonResponse;
         //return json_encode($output);
         return $output;
     }
 }
コード例 #3
0
ファイル: Model.php プロジェクト: awareness/aware
 /**
  * Validate the Model
  *    runs the validator and binds any errors to the model
  *
  * @param array $rules
  * @param array $messages
  * @return bool
  */
 public function isValid()
 {
     $valid = true;
     $data = $this->getDirty();
     $rules = $this->exists ? $this->getRules($data) : $this->getRules();
     if ($rules) {
         $validator = Validator::make($data, $rules, $this->getMessages());
         $valid = $validator->passes();
     }
     if (!$valid) {
         $this->errorBag = $validator->errors();
     } elseif ($this->errorBag && $this->errorBag->any()) {
         $this->errorBag = new MessageBag();
     }
     return $valid;
 }
コード例 #4
0
ファイル: Environment.php プロジェクト: creolab/alert
 /**
  * Show specific alert type
  * @param  string $type
  * @return string
  */
 public function render($type = null)
 {
     if ($this->bag->any()) {
         $output = '';
         foreach ($this->bag->getMessages() as $type => $messages) {
             // Class for opening tag
             $class = $type == 'error' ? 'danger' : $type;
             // Start collection
             $output .= $this->config->get('alert::collection_open', '<div class="alert alert-' . $class . '">') . PHP_EOL;
             foreach ($messages as $message) {
                 // Prepare output
                 $output .= $this->config->get('alert::alert_open', '<p>');
                 $output .= $message;
                 $output .= $this->config->get('alert::alert_close', '</p>');
             }
             // Close it
             $output .= $this->config->get('alert::collection_close', '</div>') . PHP_EOL;
         }
         return $output;
     }
 }
コード例 #5
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');
 }
コード例 #6
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');
 }