當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Request::validate方法代碼示例

本文整理匯總了PHP中App\Http\Requests\Request::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Request::validate方法的具體用法?PHP Request::validate怎麽用?PHP Request::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在App\Http\Requests\Request的用法示例。


在下文中一共展示了Request::validate方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validate

 /**
  * Overwrite the validation method
  * only needs to be triggered when certain properties are set.
  * This is to enable patch updates.
  *
  * @return
  */
 public function validate()
 {
     $input = request()->input();
     if ($this->validationRequired($input)) {
         return parent::validate();
     }
 }
開發者ID:weopendata,項目名稱:medea,代碼行數:14,代碼來源:UpdateUserRequest.php

示例2: validate

 /**
  * Validate the class instance.
  * This overrides the default invocation to provide additional rules after the controller is setup.
  *
  * @return void
  */
 public function validate()
 {
     $board = $this->board;
     $user = $this->user;
     if (is_null($board) || is_null($user)) {
         return parent::validate();
     }
     $validator = $this->getValidatorInstance();
     $messages = $validator->errors();
     // Check global flood.
     $lastPost = Post::where('author_ip', inet_pton($this->ip()))->where('created_at', '>', \Carbon\Carbon::now()->subSeconds(30))->op()->first();
     if ($lastPost instanceof Post) {
         $timeDiff = 30 - $lastPost->created_at->diffInSeconds();
         $messages = $validator->errors();
         $messages->add("flood", trans_choice("validation.custom.thread_flood", $timeDiff, ['time_left' => $timeDiff]));
         $this->failedValidation($validator);
         return;
     }
     // Ban check.
     $ban = Ban::getBan($this->ip(), $board->board_uri);
     if ($ban) {
         $messages = $validator->errors();
         $messages->add("body", trans("validation.custom.banned"));
         $this->ban = $ban;
         $this->failedValidation($validator);
         return;
     }
     // Board-level setting validaiton.
     $validator->sometimes('captcha', "required|captcha", function ($input) use($board) {
         return !$board->canPostWithoutCaptcha($this->user);
     });
     if (!$validator->passes()) {
         $this->failedValidation($validator);
     } else {
         if (!$this->user->canAdminConfig() && $board->canPostWithoutCaptcha($this->user)) {
             // Check last post time for flood.
             $floodTime = site_setting('postFloodTime');
             if ($floodTime > 0) {
                 $lastPost = Post::getLastPostForIP();
                 if ($lastPost) {
                     $floodTimer = clone $lastPost->created_at;
                     $floodTimer->addSeconds($floodTime);
                     if ($floodTimer->isFuture()) {
                         $messages->add("body", trans("validation.custom.post_flood", ['time_left' => $floodTimer->diffInSeconds()]));
                     }
                 }
             }
         }
         // Validate individual files.
         $input = $this->all();
         // Process uploads.
         if (isset($input['files'])) {
             $uploads = $input['files'];
             if (count($uploads) > 0) {
                 foreach ($uploads as $uploadIndex => $upload) {
                     // If a file is uploaded that has a specific filename, it breaks the process.
                     if (method_exists($upload, "getPathname") && !file_exists($upload->getPathname())) {
                         $messages->add("files.{$uploadIndex}", trans("validation.custom.file_corrupt", ["filename" => $upload->getClientOriginalName()]));
                     }
                 }
             }
         }
     }
     if (count($validator->errors())) {
         $this->failedValidation($validator);
     }
 }
開發者ID:spanishtech,項目名稱:infinity-next,代碼行數:73,代碼來源:PostRequest.php

示例3: validate

 public function validate()
 {
     $lang = $this->route('lang');
     $this->merge(compact('lang'));
     parent::validate();
 }
開發者ID:ahk-ch,項目名稱:chamb.net,代碼行數:6,代碼來源:SetLanguageRequest.php

示例4: validate

 /**
  * Validate the class instance.
  * This overrides the default invocation to provide additional rules after the controller is setup.
  *
  * @return void
  */
 public function validate()
 {
     $board = $this->board;
     $user = $this->user;
     if (!$board || !$user) {
         return parent::validate();
     }
     $validator = $this->getValidatorInstance();
     $validator->sometimes('captcha', "required|captcha", function ($input) use($board) {
         return !$board->canPostWithoutCaptcha($this->user);
     });
     if (!$validator->passes()) {
         $this->failedValidation($validator);
     } else {
         // This is a hack, but ...
         // If a file is uploaded that has a specific filename, it breaks the process.
         $input = $this->all();
         // Process uploads.
         if (isset($inpput['files'])) {
             $uploads = $input['files'];
             if (count($uploads) > 0) {
                 foreach ($uploads as $uploadIndex => $upload) {
                     if (method_exists($upload, "getPathname") && !file_exists($upload->getPathname())) {
                         $messages = $validator->errors();
                         $messages->add("files.{$uploadIndex}", trans("validation.custom.file_corrupt", ["filename" => $upload->getClientOriginalName()]));
                         $this->failedValidation($validator);
                         break;
                     }
                 }
             }
         }
     }
 }
開發者ID:ee-ee,項目名稱:infinity-next,代碼行數:39,代碼來源:PostRequest.php

示例5: validate

 /**
  * Validate the class instance.
  * This overrides the default invocation to provide additional rules after the controller is setup.
  *
  * @return void
  */
 public function validate()
 {
     $board = $this->board;
     $user = $this->user;
     if (!$board || !$user) {
         return parent::validate();
     }
     $validator = $this->getValidatorInstance();
     $validator->sometimes('captcha', "required|captcha", function ($input) use($board) {
         return !$board->canPostWithoutCaptcha($this->user);
     });
     if (!$validator->passes()) {
         $this->failedValidation($validator);
     } else {
         if (!$this->user->canAdminConfig() && $board->canPostWithoutCaptcha($this->user)) {
             // Check last post time for flood.
             $floodTime = site_setting('postFloodTime');
             if ($floodTime > 0) {
                 $lastPost = Post::getLastPostForIP();
                 if ($lastPost) {
                     $floodTimer = clone $lastPost->created_at;
                     $floodTimer->addSeconds($floodTime);
                     if ($floodTimer->isFuture()) {
                         $messages = $validator->errors();
                         $messages->add("body", trans("validation.custom.post_flood", ['time_left' => $floodTimer->diffInSeconds()]));
                         $this->failedValidation($validator);
                     }
                 }
             }
         }
         // This is a hack, but ...
         // If a file is uploaded that has a specific filename, it breaks the process.
         $input = $this->all();
         // Process uploads.
         if (isset($inpput['files'])) {
             $uploads = $input['files'];
             if (count($uploads) > 0) {
                 foreach ($uploads as $uploadIndex => $upload) {
                     if (method_exists($upload, "getPathname") && !file_exists($upload->getPathname())) {
                         $messages = $validator->errors();
                         $messages->add("files.{$uploadIndex}", trans("validation.custom.file_corrupt", ["filename" => $upload->getClientOriginalName()]));
                         $this->failedValidation($validator);
                         break;
                     }
                 }
             }
         }
     }
 }
開發者ID:Ryangr0,項目名稱:infinity-next,代碼行數:55,代碼來源:PostRequest.php


注:本文中的App\Http\Requests\Request::validate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。