最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Missing validation in Laravel in some cases when using Form Request - Stack Overflow

programmeradmin2浏览0评论

I have got a problem with Laravel.

I have created a custom Form Request - let's call it CustomFormRequest. It is authorized and have got rules as it should be.

In one of the classes I use this request this way:

class CustomClass {

   public function __construct(CustomFormRequest $customFormRequest) {

      // Code only run from there after a successful validation.
      // If there was an error in validation then HTTP 422 error was send by Laravel

   }

}

From a Controller, usually I use this CustomClass in this way:

public function Custom(CustomClass $customClass) {

   // Code only run from there after a successful validation.

}

But, sometimes, I also try to access this class in this way from either a controller or from other class:

$customRequest = new CustomRequest();
$customRequest->sendMethod('POST');
$customRequest->request->add(...array of data...);
new CustomClass($customRequest);

But it turned out when I use the class this way Laravel somehow skips the validation and even when I gave an invalid data for the class, it will run and tries to put those invalid data into the database!

Is there anything that I missing!? Is another line needed to enforcing the validation!?

Thanks for any further help!

I also tried using $request->validate($request->rules()) but it leads to ERR_TOO_MANY_REDIRECTS.

发布评论

评论列表(0)

  1. 暂无评论