Beispiel #1
0
 /**
  * Manipulate the input before performing validation
  *
  * @return Validator;
  */
 protected function getValidatorInstance()
 {
     // Set default values.
     collect(['project_id', 'estimatedDuration', 'start', 'minutes'])->each(function ($field) {
         if ($field === 'start') {
             $value = sprintf('%s %s', $this->input($field . 'Date', ''), $this->input($field . 'Time', ''));
             $value = new Carbon($value);
         }
         if ($field === 'project_id') {
             $value = $this->input($field, 0);
         }
         if ($field === 'estimatedDuration') {
             $value = $this->input($field, 0);
         }
         if ($field === 'minutes') {
             $value = 0;
             $start = $this->input('startTime', 0);
             $end = $this->input('endTime', 0);
             if ($start && $end) {
                 $value = (strtotime($end) - strtotime($start)) / 60;
             }
         }
         $this->merge([$field => $value]);
     });
     return parent::getValidatorInstance();
 }
 /**
  * Overrides getValidatorInstance so we can apply sometimes function
  * @return 
  */
 protected function getValidatorInstance()
 {
     //todo: change validator to handle categories correctly
     return parent::getValidatorInstance();
     //$validator->sometimes('dob', 'valid_date', function($input));
     //return $validator;
 }
 protected function getValidatorInstance()
 {
     /*
     	Automatic generate slug
     */
     $this->merge(['slug' => turkish_slug($this->input('title'))]);
     return parent::getValidatorInstance();
 }
Beispiel #4
0
 /**
  * Manipulate the input before performing validation
  *
  * @return Validator;
  */
 protected function getValidatorInstance()
 {
     // Set default values.
     collect(['active', 'billable', 'taxDeducted'])->each(function ($field) {
         $value = $this->input($field, 0);
         $this->merge([$field => $value]);
     });
     return parent::getValidatorInstance();
 }
Beispiel #5
0
 protected function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->after(function () use($validator) {
         $input = $this->all();
         //	dd($input);
         $this->validateTaskMember($this, $validator);
         $this->validateSubtasks($input['subtasks'], $validator);
     });
     return $validator;
 }
Beispiel #6
0
 protected function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->after(function () use($validator) {
         $input = $this->input();
         if (User::isNameExist($input['firstname'], $input['lastname'], $input['middleinitial'])) {
             $validator->errors()->add('firstname', "User named {$input['firstname']} {$input['lastname']} already exists.");
         }
         // add validation for contact_no
     });
     return $validator;
 }
 /**
  * Validate for unique file hash
  * @return \Illuminate\Validation\Validator
  */
 public function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->after(function () use($validator) {
         if (!is_null($this->file('file')) && $this->file('file')->isValid()) {
             $file = $this->file('file');
             $csv_mime_types = ['text/csv', 'text/plain', 'application/csv', 'text/comma-separated-values', 'application/excel', 'application/vnd.ms-excel', 'application/vnd.msexcel', 'text/anytext', 'application/octet-stream', 'application/txt'];
             if (!in_array($file->getMimeType(), $csv_mime_types)) {
                 $validator->errors()->add('file', 'The file must be a CSV or Excel.');
             }
         }
     });
     return $validator;
 }
Beispiel #8
0
 /**
  * Modifikasi data input sebelum divalidasi, input juga akan diteruskan ke
  * LeadController untuk mengurangi modifikasi input sebelum menyimpan ke
  * database.
  *
  * @return Validator
  */
 public function getValidatorInstance()
 {
     $input = $this->all();
     // Menentukan jika kontraktor mengisi survey atau tidak
     // sama sekali
     if (!array_key_exists('s2_data', $input['lead']) && !array_key_exists('geo_data', $input['lead']) && !array_key_exists('chem_data', $input['lead']) && !array_key_exists('grav_data', $input['lead']) && !array_key_exists('elec_data', $input['lead']) && !array_key_exists('resi_data', $input['lead']) && !array_key_exists('oter_data', $input['lead'])) {
         $input['lead']['survey'] = null;
     } else {
         $input['lead']['survey'] = 1;
     }
     // Menggabungkan 3 field "Initiation date" menjadi satu field
     $input['lead']['initiate'] = Carbon::createFromDate($input['lead']['initiate']['year'], $input['lead']['initiate']['month'], $input['lead']['initiate']['day'])->toDateString();
     $input['lead']['latitude'] = $input['lead']['latitude_degree'] . "," . $input['lead']['latitude_minute'] . "," . $input['lead']['latitude_second'] . "," . $input['lead']['latitude_cardinal'];
     $input['lead']['longitude'] = $input['lead']['longitude_degree'] . "," . $input['lead']['longitude_minute'] . "," . $input['lead']['longitude_second'] . ",E";
     $this->getInputSource()->replace($input);
     return parent::getValidatorInstance();
 }
Beispiel #9
0
 protected function getValidatorInstance()
 {
     $prefix = $this->model . '_';
     $all = $this->all();
     foreach ($all as $key => $value) {
         if (preg_match("/{$prefix}(?<name>.*)/", $key, $match)) {
             $name = $match['name'];
             $this[$name] = $value;
         }
     }
     if (!empty($this->alias)) {
         foreach ($this->alias as $key => $value) {
             $temp = $this[$key];
             if (empty($temp)) {
                 $this[$prefix . $key] = $this[$key] = ConvertHelper::alias($this[$value]);
             }
         }
     }
     return parent::getValidatorInstance();
 }
 /**
  * Validate for unique file hash
  * @return \Illuminate\Validation\Validator
  */
 public function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->after(function () use($validator) {
         if ($this->isMethod('POST')) {
             if ($this->file('file')->isValid()) {
                 $file = $this->file('file');
                 $hash = getFileHash($file->getPathName());
                 $contractService = app('App\\Nrgi\\Services\\Contract\\ContractService');
                 if ($contract = $contractService->getContractIfFileHashExist($hash)) {
                     $message = trans("The contract file is already present in our system. Please check the following Title of contract with which the uploaded file is linked and make necessary updates.");
                     $message .= sprintf("<div><a target='_blank' href='%s'>%s</a></div>", route('contract.show', $contract->id), $contract->title);
                     $validator->errors()->add('file', $message);
                 }
             } else {
                 $validator->errors()->add('file', $this->file('file')->getError());
             }
         }
     });
     return $validator;
 }
Beispiel #11
0
 protected function getValidatorInstance()
 {
     $dateHelper = new DateHelper();
     $data = $this->all();
     $data['name'] = $data['event-name'];
     $data['slug'] = str_slug($data['event-name']);
     $data['description'] = strip_tags($data['event-description'], '<br>');
     $data['description_plain'] = strip_tags($data['event-description'], '<br>');
     $data['street'] = $data['event-street'];
     $data['city'] = $data['event-city'];
     $data['state'] = $data['event-state'];
     $data['zip'] = $data['event-zip'];
     $data['date_start'] = $dateHelper->getStartTimeFromRange($data['daterangepicker']);
     if ($data['daterangepicker']) {
         $data['date_end'] = $dateHelper->getEndTimeFromRange($data['daterangepicker']);
     } else {
         $data['date_end'] = $data['daterangepicker'];
     }
     $this->getInputSource()->replace($data);
     /*modify data before send to validator*/
     return parent::getValidatorInstance();
 }
 /**
  * @return \Illuminate\Contracts\Validation\Validator
  */
 protected function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     if (is_null($this->work)) {
         return $validator;
     }
     if ($this->work->crops->where('id', $this->input('crop_id'))->isEmpty()) {
         // 作業内容の選択が不正
         $validator->after(function ($validator) {
             $validator->errors()->add('work_id', trans('validation.required', ['attribute' => trans('validation.attributes.work_id')]));
         });
     }
     if ($this->work->use_pest_control) {
         if (empty(session()->get('workRecord.pesticides'))) {
             // 農薬が未選択
             $validator->after(function ($validator) {
                 $validator->errors()->add('pesticide', trans('validation.required', ['attribute' => trans('validation.attributes.pesticide')]));
             });
         }
     }
     return $validator;
 }
Beispiel #13
0
 /**
  * Get the validator instance for the request.
  *
  * @return \Illuminate\Contracts\Validation\Validator
  */
 protected function getValidatorInstance()
 {
     $domain = false === ($pos = strpos($email = $this->input('email', ''), '@')) ? '' : substr($email, $pos + 1);
     $this->merge(['domain' => $domain]);
     return parent::getValidatorInstance();
 }